Execute additional commands after creating database?

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

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.

Have you successfully run any tests using rails baked-in testing?

[...]

> Now I installed RSpec and tried running some tests.

Have you successfully run any tests using rails baked-in testing?

I never used them before. I tried running them now and got the same error.

Well, it started promising but then got ughly. I'm not quite sure what exactly went wrong but I suspect it's globalize's fault.

Here's the log: ** 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 dropdb: database removal failed: ERROR: must be owner of database rpps_test createdb: database creation failed: ERROR: permission denied to create database ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load NOTICE: CREATE TABLE will create implicit sequence "globalize_countries_id_seq" for serial column "globalize_countries.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "globalize_countries_pkey" for table "globalize_countries" rake aborted! PGError: ERROR: duplicate key violates unique constraint "pg_attribute_relid_attnam_index" : CREATE INDEX "index_globalize_countries_on_code" ON rpps.globalize_countries ("code", "code")