After migrating my development database, I'm unable to run rails db:test:prepare
.
My application uses the db/structure.sql
file to update the test database:
# config/application.rb
config.active_record.schema_format = :sql
When I run rails db:migrate
(which also runs db:structure:dump
), my db/structure.sql
is updated. Unfortunately, it now contains this line near the top after updating:
CREATE SCHEMA public;
This will bomb when loaded into a database that already contains the public
schema.
I can manually update that line and the SQL dump loads successfully:
CREATE SCHEMA IF NOT EXISTS public;
...but I don't want to do that every time.
I expect the test database to be built successfully from the SQL dump in db/structure.sql
when I run rails db:test:prepare
because the SQL dump should not try to create the public
schema.
structure.sql
doesn't try to create the public schema. Which version of PostgreSQL are you using? – Xanthuspsql -V
gives mepsql (PostgreSQL) 11.3
. – FreeboardCREATE SCHEMA public;
if you manuallypg_dump
your database? I'm wondering if thepg_dump
output change slightly in PostgreSQL 11 (which I don't have installed). – Xanthuspublic
schema instructure.sql
. – Freeboarddb/structure.sql
file? – Xanthusdb/structure.sql
file:-- Dumped from database version 11.3
-- Dumped by pg_dump version 11.3
– Freeboardpg_dump
does not include theCREATE SCHEMA public
line. – Freeboardpg_dump
with a--schema=<schema_name>
argument, which creates the lineCREATE SCHEMA <schema_name>
.pg_dump
gives no option to change this to...IF EXISTS...
. – Freeboardactiverecord-5.0.7.2/lib/active_record/tasks/postgresql_database_tasks.rb:45
– Freeboard