提交 e0f0afb9 编写于 作者: A Aaron Patterson

refactor schema migration table creation to the schema migration model

上级 2c667f69
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册