Reputation: 3485
When running rake db:schema:dump on an app that uses a postgres schema (i.e. schema_name.users), it looks like it's only dumping tables for the first schema in the db user's search path. Is there a way to include tables from more than one schema?
To state the problem differently:
createdb myapp
psql myapp -U postgres -c "create table stuff"
#=> creates table "stuff" in the public schema
psql myapp -U postgres -c "create schema specific_thing"
psql myapp -U postgres -c 'create table "specific_thing".users(id int)'
createuser -U postgres -S -D -R special_user
psql myapp -U postgres -c "grant all on schema specific_thing to special_user"
psql myapp -U postgres -c "ALTER USER special_user SET search_path TO specific_thing,public"
In database.yml:
...
development:
adapter: postgresql
database: stuff
username: special_user
password:
host: localhost
...
Running: rake db:schema:dump
Only dumps the users
talbe from the specific_thing
schema and ignores everything in the public schema.
Upvotes: 2
Views: 597
Reputation: 3485
So here's what I found. I don't have the code in front of me so I can't point to anything specifically, but there is some code in PostgresAdapter that identifies what the adapter considers as its available 'tables'. The adapter assumes it's always going to deal with the 'public' schema (public is actually hardcoded in the query that gets a list of tables), so my solution to the problem involved subclassing PostgresAdapter to have a different concept of what it's 'tables' are. This got me most of the way there. There were some other obstacles to overcome but everything was much more clear after fitting this piece into the puzzle. Definitely involved spending some time in the Rails source though.
Upvotes: 1