diff options
author | Kyle Rippey <kyle@avvo.com> | 2013-05-26 15:31:49 -0700 |
---|---|---|
committer | Kyle Rippey <kyle@avvo.com> | 2013-05-26 15:31:49 -0700 |
commit | aef9a4bfbd07f7d859dccbcf9d01578f1f611d4b (patch) | |
tree | d3d9e12cf88560ac58c0df12caff079967e919d2 /activerecord/lib | |
parent | c3890d38cbba97fd44f5b5a94f51ddb62a3ec71a (diff) | |
download | rails-aef9a4bfbd07f7d859dccbcf9d01578f1f611d4b.tar.gz rails-aef9a4bfbd07f7d859dccbcf9d01578f1f611d4b.tar.bz2 rails-aef9a4bfbd07f7d859dccbcf9d01578f1f611d4b.zip |
Minor refactor of ActiveRecord::SchemaMigration to remove references to Base, override table_exists method, and switch to preferred style for class method definitions.
Diffstat (limited to 'activerecord/lib')
-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 |