diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-28 09:30:54 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-28 09:30:54 -0700 |
commit | 059e4fb5949e87f64dc0f5f9d249d545d7196ab1 (patch) | |
tree | c4645740449bf57bdfe31506cb8d24a32e27ff54 | |
parent | 6ecc360d8867c0db1eee9371f4d44bbd0e932070 (diff) | |
parent | aef9a4bfbd07f7d859dccbcf9d01578f1f611d4b (diff) | |
download | rails-059e4fb5949e87f64dc0f5f9d249d545d7196ab1.tar.gz rails-059e4fb5949e87f64dc0f5f9d249d545d7196ab1.tar.bz2 rails-059e4fb5949e87f64dc0f5f9d249d545d7196ab1.zip |
Merge pull request #10766 from kylerippey/minor_schema_migration_refactor
Minor refactor of ActiveRecord::SchemaMigration
-rw-r--r-- | activerecord/lib/active_record/schema_migration.rb | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb index 6077144265..fee19b1096 100644 --- a/activerecord/lib/active_record/schema_migration.rb +++ b/activerecord/lib/active_record/schema_migration.rb @@ -4,31 +4,37 @@ require 'active_record/base' module ActiveRecord class SchemaMigration < ActiveRecord::Base + class << self - def self.table_name - "#{Base.table_name_prefix}schema_migrations#{Base.table_name_suffix}" - end + def table_name + "#{table_name_prefix}schema_migrations#{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_schema_migrations#{table_name_suffix}" + end - def self.create_table(limit=nil) - unless connection.table_exists?(table_name) - version_options = {null: false} - version_options[:limit] = limit if limit + def table_exists? + connection.table_exists?(table_name) + end + + 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 + 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 end |