diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 6b05de36148ac..0cac6d1391674 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -414,15 +414,7 @@ def dump_schema_information #:nodoc: # Should not be called normally, but this operation is non-destructive. # The migrations module handles this automatically. def initialize_schema_migrations_table - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - - unless table_exists?(sm_table) - create_table(sm_table, :id => false) do |schema_migrations_table| - schema_migrations_table.column :version, :string, :null => false - end - add_index sm_table, :version, :unique => true, - :name => "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}" - end + ActiveRecord::SchemaMigration.create_table end def assume_migrated_upto_version(version, migrations_paths = ActiveRecord::Migrator.migrations_paths) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index cd0466711033d..2a9139749db5a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -669,7 +669,7 @@ def initialize(direction, migrations, target_version = nil) validate(@migrations) - Base.connection.initialize_schema_migrations_table + ActiveRecord::SchemaMigration.create_table end def current_version diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb index fe47db10f0f73..20e3cbb1f66b5 100644 --- a/activerecord/lib/active_record/schema_migration.rb +++ b/activerecord/lib/active_record/schema_migration.rb @@ -8,6 +8,24 @@ def self.table_name Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix end + def self.create_table + unless connection.table_exists?(table_name) + connection.create_table(table_name, :id => false) do |t| + t.column :version, :string, :null => false + end + connection.add_index table_name, :version, :unique => true, + :name => "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}" + end + end + + def self.drop_table + if connection.table_exists?(table_name) + connection.remove_index table_name, :version, :unique => true, + :name => "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}" + connection.drop_table(table_name) + end + end + def version super.to_i end diff --git a/activerecord/test/cases/migrator_test.rb b/activerecord/test/cases/migrator_test.rb index a2e5fd21e24a7..143aadd83395a 100644 --- a/activerecord/test/cases/migrator_test.rb +++ b/activerecord/test/cases/migrator_test.rb @@ -19,6 +19,7 @@ def down; @went_down = true; end def setup super + ActiveRecord::SchemaMigration.create_table ActiveRecord::SchemaMigration.delete_all rescue nil end