class Seed::Snapshot
Public Class Methods
new(configuration)
click to toggle source
# File lib/seed/snapshot.rb, line 3 def initialize(configuration) @configuration = configuration end
Public Instance Methods
clean()
click to toggle source
# File lib/seed/snapshot.rb, line 38 def clean unless exist_path? puts "Dump file does not exist for current schema." return end version_path = @configuration.current_version_path File.delete(version_path) end
dump(classes = [], ignore_classes = [], force_dump = false)
click to toggle source
# File lib/seed/snapshot.rb, line 7 def dump(classes = [], ignore_classes = [], force_dump = false) @configuration.make_tmp_dir if exist_path? && !force_dump puts 'Dump file already exists for current schema.' return end Mysql.dump( @configuration.current_version_path, options.merge({ tables: tables(classes), ignore_tables: ignore_tables(ignore_classes) }) ) end
exist_path?()
click to toggle source
# File lib/seed/snapshot.rb, line 48 def exist_path? version_path = @configuration.current_version_path File.exist?(version_path) end
ignore_tables(classes)
click to toggle source
# File lib/seed/snapshot.rb, line 70 def ignore_tables(classes) db = @configuration.database_options[:database] # mysqldump `--ignore-table` options require database name. tables(classes).push('schema_migrations').map {|t| "#{db}.#{t}" } end
options()
click to toggle source
# File lib/seed/snapshot.rb, line 53 def options db = @configuration.database_options { username: db[:username], password: db[:password], host: db[:host], port: db[:port], database: db[:database] } end
restore()
click to toggle source
# File lib/seed/snapshot.rb, line 24 def restore @configuration.make_tmp_dir unless exist_path? puts "Dump file does not exist for current schema." return end Mysql.restore( @configuration.current_version_path, options ) end
tables(classes)
click to toggle source
# File lib/seed/snapshot.rb, line 64 def tables(classes) classes.map do |cls| cls.table_name end end