I'm writing some code that accesses some lagacy database on PostgreSQL. Since the old database had some really ughly and weird naming conventions (like CamelCase). To work around this I created a second schema (named rails) in the same database and gave the tables and fields some rails-friendly names. The database user that Rails uses has its search_path set to the rails schema. That way Rails won't try to find models for the legacy tables. This worked fine so far. I even got triggers working to be able to write into the real tables.
Now I installed RSpec and tried running some tests. This failed because the test database gets recreated on every test run. Since I specified config.active_record.table_name_prefix to be "rails." and a fresh database doesn't contain that schema yet it fails miserably. I tried executing a "create schema rails" in the first migration but somehow Globalize bit me in my ass because it tries to create it's own tables first although there is no such migration in db/migrations. What can I do?
To illustrate, this is what it looks like.
% rake spec --trace (in /Users/fastjack/Sites/rpps) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load rake aborted! PGError: ERROR: schema "rails" does not exist : CREATE TABLE rails.globalize_countries ("id" serial primary key, "code" character varying(2) DEFAULT NULL, "english_name" character varying(255) DEFAULT NULL, "date_format" character varying(255) DEFAULT NULL, "currency_format" character varying(255) DEFAULT NULL, "currency_code" character varying(3) DEFAULT NULL, "thousands_sep" character varying(2) DEFAULT NULL, "decimal_sep" character varying(2) DEFAULT NULL, "currency_decimal_sep" character varying(2) DEFAULT NULL, "number_grouping_scheme" character varying(255) DEFAULT NULL) /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/connection_adapters/abstract_adapter.rb:128:in `log' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/connection_adapters/postgresql_adapter.rb:152:in `execute' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/migration.rb:275:in `send' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/migration.rb:275:in `method_missing' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/migration.rb:259:in `say_with_time' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/migration.rb:259:in `say_with_time' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/migration.rb:273:in `method_missing' ./db/schema.rb:7 /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/schema.rb:43:in `instance_eval' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/lib/ active_record/schema.rb:43:in `define' ./db/schema.rb:5 /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:488:in `load' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:488:in `load' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' /Users/fastjack/Sites/rpps/config/../vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:488:in `load' /Users/fastjack/Sites/rpps/config/../vendor/rails/railties/lib/tasks/ databases.rake:31 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /Users/fastjack/Sites/rpps/config/../vendor/rails/railties/lib/tasks/ databases.rake:76 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /Users/fastjack/Sites/rpps/config/../vendor/rails/railties/lib/tasks/ databases.rake:153 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:369:in `invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `send' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:368:in `invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:361:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 /usr/local/bin/rake:16:in `load' /usr/local/bin/rake:16