class DataMigrate::Data
Provides the definition method for data_schema.rb
Public Instance Methods
define(info)
click to toggle source
This method is based on the following two methods
ActiveRecord::Schema#define ActiveRecord::ConnectionAdapters::SchemaStatements #assume_migrated_upto_version
# File lib/data_migrate/data_schema.rb, line 11 def define(info) DataMigrate::DataMigrator.create_data_schema_table return if info[:version].blank? version = info[:version].to_i unless migrated.include?(version) execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" end insert(version) end
Private Instance Methods
insert(version)
click to toggle source
# File lib/data_migrate/data_schema.rb, line 42 def insert(version) inserted = Set.new (versions - migrated).each do |v| if inserted.include?(v) raise "Duplicate data migration #{v}. Please renumber your data " \ "migrations to resolve the conflict." elsif v < version execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" inserted << v end end end
migrated()
click to toggle source
# File lib/data_migrate/data_schema.rb, line 27 def migrated @migrated ||= select_values("SELECT version FROM #{sm_table}").map(&:to_i) end
sm_table()
click to toggle source
# File lib/data_migrate/data_schema.rb, line 55 def sm_table quote_table_name(table_name) end
table_name()
click to toggle source
# File lib/data_migrate/data_schema.rb, line 59 def table_name DataMigrate::RailsHelper.data_schema_migration.table_name end
versions()
click to toggle source
# File lib/data_migrate/data_schema.rb, line 31 def versions @versions ||= Set.new.tap do |versions| DataMigrate::DataMigrator.migrations_paths.each do |path| Dir.foreach(path) do |file| match_data = DataMigrate::DataMigrator.match(file) versions << match_data[1].to_i if match_data end end end end