Permalink
Browse files

refactor schema migration table creation to the schema migration model

  • Loading branch information...
1 parent 2c667f6 commit e0f0afb97572e80b0910302d983cf9fa8dabb268 @tenderlove tenderlove committed Jan 13, 2012
@@ -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)
@@ -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
@@ -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
@@ -19,6 +19,7 @@ def down; @went_down = true; end
def setup
super
+ ActiveRecord::SchemaMigration.create_table
ActiveRecord::SchemaMigration.delete_all rescue nil
end

0 comments on commit e0f0afb

Please sign in to comment.