4
votes

I have a Rails 3.2.1 project that I'm trying to run my specs on.

When I run: rake

rake aborted! PG::Error: ERROR: invalid value for parameter "search_path": "example" DETAIL: schema "example" does not exist : SET search_path TO example

From what I can work out, rake db:test:prepare drops the test database and then attempts to recreate it from the schema.rb. The thing is, database.yml has the line

schema_search_path: example

so when it tries to reconnect, it fails with the above error.

I think my question is, how can I get rake db:test:prepare to setup the schema_path too?

2

2 Answers

0
votes

One solution is to add a bit of code to the db:create task that creates the schema. Put this in a rake task, for exmaple 'APP_ROOT/lib/tasks/db_create_schema.rake'

namespace :db do
  task :create do
    config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'})
    ActiveRecord::Base.establish_connection(config)
    ActiveRecord::Base.connection.execute("CREATE SCHEMA schema_name")
  end
end

https://gist.github.com/4280172

-1
votes

You should set the schema_search_path in your config/database.yml

e.g.

development:
  adapter: postgresql
  encoding: unicode
  database: test
  pool: 5
  username: user
  password: password
  #host: localhost
  #port: 5432
  # Schema search path. The server defaults to $user,public
  schema_search_path: example