This project is archived and is in readonly mode.
rake db:test:clone_structure might fail with multiple schemas in postgres.
Reported by Juan Manuel Cuello | March 22nd, 2011 @ 04:18 AM
Currently, when pg_dump is executed in db:structure:dump for postgres adapter, all the schemas are dumped to the sql file and 'INSERT' statements for the rails schema version are added at the end of the file.
If many schemas are dumped, the last 'SET search_path ..' statement in the sql file might not refer to the schema where schema_migrations table belongs to. An attempt to run db:test:clone_structure fails with 'ERROR: relation "schema_migrations" does not exist' when executing the INSERTS because the table is not in the last set schema inside the sql file.
This patch adds the statement "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path}" after the pg_dump statements but before the INSERT statements for the schema_migrations table.
Comments and changes to this ticket
-
Juan Manuel Cuello April 21st, 2011 @ 09:07 PM
It is easy to reproduce the problem. These are the steps:
Create a Rails application that uses postgresql:
$ rails new postgres_clone -d postgresql $ cd postgres_clone
Then create a migration:
#db/migrate/20110421194621_my_migration.rb class MyMigration < ActiveRecord::Migration def self.up connection.execute 'CREATE SCHEMA z_schema;' connection.execute 'CREATE TABLE z_schema.table1 (id integer, name varchar[255]);' connection.execute 'CREATE UNIQUE INDEX unique_table1_name ON z_schema.table1 USING btree (name);' end end
And the run:
$ rake db:create $ rake db:migrate $ rake db:test:clone_structure
(in /home/juan/projects/postgres_clone) psql:/home/juan/projects/postgres_clone/db/development_structure.sql:75: ERROR: relation "schema_migrations" does not exist LÍNEA 1: INSERT INTO schema_migrations (version) VALUES ('20110421194... ^
-
Juan Manuel Cuello May 13th, 2011 @ 09:39 PM
The first patch I attached does not apply anymore because 'databases.rake' changed.
This is the same patch but created recently from 'master'.
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>