diff options
author | Marcel Molina <marcel@vernix.org> | 2005-09-26 21:30:12 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2005-09-26 21:30:12 +0000 |
commit | 1465f9cee27a55b5c13bad35bac74be119097f17 (patch) | |
tree | a12a659c24b00a53a1c8a49f87d1080a7b3f6a0a /activerecord/lib/active_record | |
parent | 0f276de5127a1ede5232026ffed36bae086e6aec (diff) | |
download | rails-1465f9cee27a55b5c13bad35bac74be119097f17.tar.gz rails-1465f9cee27a55b5c13bad35bac74be119097f17.tar.bz2 rails-1465f9cee27a55b5c13bad35bac74be119097f17.zip |
Make migrations honor table name prefixes and suffixes.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2352 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 15 |
2 files changed, 16 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 81ddb3e2bb..d7aefc9a82 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -102,8 +102,8 @@ module ActiveRecord def initialize_schema_information #:nodoc: begin - execute "CREATE TABLE schema_info (version #{type_to_sql(:integer)})" - execute "INSERT INTO schema_info (version) VALUES(0)" + execute "CREATE TABLE #{ActiveRecord::Migrator.schema_info_table_name} (version #{type_to_sql(:integer)})" + execute "INSERT INTO #{ActiveRecord::Migrator.schema_info_table_name} (version) VALUES(0)" rescue ActiveRecord::StatementInvalid # Schema has been intialized end @@ -112,7 +112,7 @@ module ActiveRecord def dump_schema_information #:nodoc: begin if (current_schema = ActiveRecord::Migrator.current_version) > 0 - return "INSERT INTO schema_info (version) VALUES (#{current_schema});" + return "INSERT INTO #{ActiveRecord::Migrator.schema_info_table_name} (version) VALUES (#{current_schema});" end rescue ActiveRecord::StatementInvalid # No Schema Info diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 587fbf852d..fcb5ad82de 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -142,6 +142,7 @@ module ActiveRecord private def method_missing(method, *arguments, &block) + arguments[0] = Migrator.proper_table_name(arguments.first) unless arguments.empty? ActiveRecord::Base.connection.send(method, *arguments, &block) end end @@ -169,9 +170,19 @@ module ActiveRecord self.new(:down, migrations_path, target_version).migrate end + def schema_info_table_name + Base.table_name_prefix + "schema_info" + Base.table_name_suffix + end + def current_version - (Base.connection.select_one("SELECT version FROM schema_info") || {"version" => 0})["version"].to_i + (Base.connection.select_one("SELECT version FROM #{schema_info_table_name}") || {"version" => 0})["version"].to_i end + + def proper_table_name(name) + # Use the ActiveRecord objects own table_name, or pre/suffix from ActiveRecord::Base if name is a symbol/string + name.table_name rescue "#{ActiveRecord::Base.table_name_prefix}#{name}#{ActiveRecord::Base.table_name_suffix}" + end + end def initialize(direction, migrations_path, target_version = nil) @@ -222,7 +233,7 @@ module ActiveRecord end def set_schema_version(version) - Base.connection.update("UPDATE schema_info SET version = #{down? ? version.to_i - 1 : version.to_i}") + Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{down? ? version.to_i - 1 : version.to_i}") end def up? |