Rails console search path and Postgres

1.2k Views Asked by At

I need to add a new user to my app's Postgres User table located in the test schema. When I access the console, rails automatically sets the search path to "$user",public and the new user record is saved to the public schema, not the test schema. Is there a way to add records to the User table within the test schema using the console?

2

There are 2 best solutions below

0
On BEST ANSWER

rails automatically sets the search path to

No, it's not Rails - it's Postgres doing that. It's the default search path defined in Postgres. See the manual for details: http://www.postgresql.org/docs/current/static/ddl-schemas.html#DDL-SCHEMAS-PATH

If you want a different search path for that user, use alter user to change the user's search path, e.g.:

alter user foo set search_path = 'public';
0
On

I don't think that the rails-console is very well suited to do administrative tasks. You are also specifying the schema in the database.yaml I guess you would need to create a new connection in your console.