This project is archived and is in readonly mode.
schema_migrations already exists error on db:migrate with two-database app
-
Wade Stebbings
I have not yet created a unique unit-test for this issue, but I've started looking into it.
To recreate the problem, a part of the description which skimmed-over in the description above, I have these things going on in my rails app:
- The app connects to two databases, one as the natural rails database, and one read-only metadata database which is quite huge. Models for the metadata database inherit from an abstract class called Metadata:
class Metadata < ActiveRecord::Base
self.abstract_class = true
def self.database_name
metadata = "#{RAILS_ENV}_metadata" configurations[metadata]['database']end
def self.connect_to_metadata_database
metadata = "#{RAILS_ENV}_metadata" @schema_prefix = Metadata.database_name + '.' self.establish_connection metadata puts "Connected to #{metadata.inspect}"end
connect_to_metadata_database
def self.table_name_prefix
@schema_prefixend
end
- Also, in order to deal with another problem with allowing joins to occur across the two databases, I created an initializer file, which looks like this:
class ActiveRecord::Base
def self.set_schema_prefix@@schema_prefix = configurations[RAILS_ENV]['database'] + '.'end set_schema_prefix def self.table_name_prefix
@@schema_prefixend end
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def prefix_tablesself.tables.map{|t| @@schema_prefix + t}end def self.set_schema_prefix
@@schema_prefix = ActiveRecord::Base.configurations[RAILS_ENV]['database'] + '.'end set_schema_prefix end
-
Wade Stebbings
code-formatting got messed up above, here's another try..
class Metadata < ActiveRecord::Base self.abstract_class = true def self.database_name metadata = "#{RAILS_ENV}_metadata" configurations[metadata]['database'] end def self.connect_to_metadata_database metadata = "#{RAILS_ENV}_metadata" @schema_prefix = Metadata.database_name + '.' self.establish_connection metadata puts "Connected to #{metadata.inspect}" end connect_to_metadata_database def self.table_name_prefix @schema_prefix end endclass ActiveRecord::Base def self.set_schema_prefix @@schema_prefix = configurations[RAILS_ENV]['database'] + '.' end set_schema_prefix def self.table_name_prefix @@schema_prefix end end class ActiveRecord::ConnectionAdapters::MysqlAdapter def prefix_tables self.tables.map{|t| @@schema_prefix + t} end def self.set_schema_prefix @@schema_prefix = ActiveRecord::Base.configurations[RAILS_ENV]['database'] + '.' end set_schema_prefix end -
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
-
Wade Stebbings
I don't believe this problem exists in rails 3.0 from looking at the code itself, as stated in my original posting. This is a rails 2 issue only. If no work on rails 2 is going to occur, even the latest of the 2.x branches, then this issue can be closed.
-
Santiago Pastorino
- State changed from stale to open
- Milestone set to 2.3.10
- Importance changed from to Low
