Reputation: 271
My Postgres database has many tables. Our web application allows administrators to update some of the tables and normal users to update others.
The user-managed tables have some foreign keys to rows in the admin-managed tables, but not vice-versa. A simplified example would be a web application where administrators managed a table Ingredients
, and users created Recipes
which had a many-to-many relationship with Ingredients
.
However, our application is much more complicated. Administrators use a rich web interface to update dozens of tables. Rather than having them do this live on prod, I'd really like to have them work in a staging environment and then overwrite those tables in prod when we're ready to release.
My problem is that the changes will include new and updated rows in those tables, and pg_dump
doesn't do upserts. And I can't simply drop all of the relevant administrator tables on prod before using pg_restore
because all of the foreign keys that reference them in the user tables will throw integrity errors.
Put another way, I have two databases with the exact same schema, and I want to overwrite a subset of tables in one database with the contents of the same tables in the other database.
Despite having complex schemas, our databases are <300mb. So scale is not a concern.
Upvotes: 0
Views: 50