This project is archived and is in readonly mode.

#6520 new
Jigar Patel

Running migrations in different PostgreSQL schemas is inconsistent

Reported by Jigar Patel | March 4th, 2011 @ 12:40 PM

Hello,

I have been researching on using multiple Postgres schemas in a single rails app. One option is to develop the entire app in one schema (default schema) and then create other shemas and dump the database structure in them. Other option is to support running migrations in specified schema and maintain the schema_migrations table in each schema.

I have made some patches, but I am not sure of the correctness of the approach. Here is what I have done -
1. Modify this method - ActiveRecord::Migrator.schema_migrations_table_name - to return the sm_table name as schema_name.table_name if the adapter is PostgreSQL.
2. Add an option of specifying the schema name in migration rake tasks.

This would result in this flow -
rake db:migrate SCHEMA=demo

Rake tasks will have following steps -
a) Set current schema search path
b) Run the migration (as it is done now)
c) Set schema_search_path to old schema search path.

Now a developer can develop in a "dev" schema, and run the migration in any specified schema or all the schemas.

Can somebody guide me, so that I can write test cases for this?

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages