Brewtarget / brewtarget

Main brewtarget source code repository.
GNU General Public License v3.0
312 stars 134 forks source link

Conversion from sqlite to postgres is broken #734

Open mikfire opened 1 year ago

mikfire commented 1 year ago

This is trying to copy a default database from sqlite to postgres.

This is a note so that I remember to investigate; nobody else needs to worry about this.

[12:21:07.823] (1dljhogqtc) ERROR : int ObjectStore::impl::insertObjectInDb(QSqlDatabase&, const QObject&, bool) 
Error executing database query  "INSERT INTO fermentable (id, name, deleted, display, folder, inventory_id, add_after_boil, amount, coarse_fine_diff, color, diastatic_power, ftype, is_mashed, ibu_gal_per_lb, max_in_batch, moisture, notes, origin, supplier, protein, recommend_mash, yield) VALUES (:id, :name, :deleted, :display, :folder, :inventory_id, :add_after_boil, :amount, :coarse_fine_diff, :color, :diastatic_power, :ftype, :is_mashed, :ibu_gal_per_lb, :max_in_batch, :moisture, :notes, :origin, :supplier, :protein, :recommend_mash, :yield);" :  
"ERROR:  insert or update on table \"fermentable\" violates foreign key constraint \"fermentable_inventory_id_fkey\"\n
DETAIL:  Key (inventory_id)=(173) is not present in table \"fermentable_in_inventory\".\n(23503) QPSQL: Unable to create query"  [database/ObjectStore.cpp:756]
matty0ung commented 1 year ago

One day maybe we'll have other PostgreSQL users! :smile: (I did use it a fair bit at work, but I never yet got around to getting it installed on my personal machine.)

AIUI, the simplest way to deal with this is to turn off constraints before the copy and turn them back on again afterwards. Eg, according to https://stackoverflow.com/questions/38112379/disable-postgresql-foreign-key-checks-for-migrations, it's SET session_replication_role = 'replica'; for the former and SET session_replication_role = 'origin'; for the latter.