Module: UseDb::Migrator
- Defined in:
- lib/use_db/migration.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/use_db/migration.rb', line 41 def self.included(base) unless base.respond_to?(:get_all_versions_without_connection_swap) base.extend(ClassMethods) base.alias_method_chain( :record_version_state_after_migrating, :connection_swap ) unless base.methods.include?(:record_version_state_after_migrating_without_connection_swap) base.class_eval do class << self alias_method_chain :get_all_versions, :connection_swap end end end end |
Instance Method Details
#record_version_state_after_migrating_with_connection_swap(version) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/use_db/migration.rb', line 67 def (version) just_migrated = migrations.detect { |m| m.version == version } load(just_migrated.filename) migration_model = just_migrated.name.constantize if migration_model.respond_to?(:database_model) ar_model = migration_model.database_model.constantize ar_model.connection.initialize_schema_migrations_table sm_table = self.class.schema_migrations_table_name @migrated_versions ||= [] if down? @migrated_versions.delete(version.to_i) ar_model.connection.update("DELETE FROM #{sm_table} WHERE version = '#{version}'") else @migrated_versions.push(version.to_i).sort! ar_model.connection.insert("INSERT INTO #{sm_table} (version) VALUES ('#{version}')") end else (version) end end |