diff options
Diffstat (limited to 'activerecord/lib/active_record/schema_migration.rb')
-rw-r--r-- | activerecord/lib/active_record/schema_migration.rb | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb index 9830abe7d8..b5038104ac 100644 --- a/activerecord/lib/active_record/schema_migration.rb +++ b/activerecord/lib/active_record/schema_migration.rb @@ -4,28 +4,48 @@ require 'active_record/base' module ActiveRecord class SchemaMigration < ActiveRecord::Base + class << self + def primary_key + nil + end - def self.table_name - "#{Base.table_name_prefix}schema_migrations#{Base.table_name_suffix}" - end + def table_name + "#{table_name_prefix}#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}" + end - def self.index_name - "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}" - end + def index_name + "#{table_name_prefix}unique_#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}" + end + + def table_exists? + connection.table_exists?(table_name) + 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 + def create_table(limit=nil) + unless table_exists? + version_options = {null: false} + version_options[:limit] = limit if limit + + connection.create_table(table_name, id: false) do |t| + t.column :version, :string, version_options + end + connection.add_index table_name, :version, unique: true, name: index_name end - connection.add_index table_name, :version, :unique => true, :name => index_name end - end - def self.drop_table - if connection.table_exists?(table_name) - connection.remove_index table_name, :name => index_name - connection.drop_table(table_name) + def drop_table + if table_exists? + connection.remove_index table_name, name: index_name + connection.drop_table(table_name) + end + end + + def normalize_migration_number(number) + "%.3d" % number.to_i + end + + def normalized_versions + pluck(:version).map { |v| normalize_migration_number v } end end |