Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rake db:test:clone_structure might fail with multiple schemas in postgres.

#6603

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.

Reported by Juan Manuel Cuello · March 22nd, 2011 @ 04:18 AM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. nhatmy
  2. Juan Manuel Cuello
    Juan Manuel Cuello

    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...
                         ^
    

    April 21st, 2011 @ 09:07 PM

  3. Juan Manuel Cuello
    Juan Manuel Cuello

    The first patch I attached does not apply anymore because 'databases.rake' changed.

    This is the same patch but created recently from 'master'.

    May 13th, 2011 @ 09:39 PM