thoughtbot / parity

Shell commands for development, staging, and production parity for Heroku apps
https://thoughtbot.com
MIT License
889 stars 57 forks source link

Don't use --clean flag with pg_restore #180

Closed croaky closed 4 years ago

croaky commented 4 years ago

I noticed some output when restoring my database:

pg_restore: dropping TABLE geographic_areas
pg_restore: from TOC entry 266; 1259 16503 TABLE geographic_areas uf1mu7mdqgl0dj
pg_restore: error: could not execute query: ERROR:  table "geographic_areas" does not exist
Command was: DROP TABLE "public"."geographic_areas";

It looks like the source of the output was the --clean flag:

--clean
  Clean (drop) database objects before recreating them. (Unless
  --if-exists is used, this might generate some harmless error messages,
  if any objects were not present in the destination database.)

https://www.postgresql.org/docs/current/app-pgrestore.html

As the docs say, these errors are harmless, but noisy.

We don't need the --clean flag because the commands Parity runs were:

dropdb --if-exists "$db"
createdb "$db"
pg_restore tmp/latest.backup --verbose --clean --no-acl --no-owner --dbname "$db"

We've already dropped the whole database, so --clean is redundant.