
GORM has certain downsides: - Code-first approach, where queries have to be translated to the Go code required to execute them. - GORM comes with its own SQLite implementation, which doesn't provide an on-connect callback. This means that new connections cannot correctly enable foreign key constraints, causing database consistency issues. [SQLC](https://sqlc.dev/) solves these issues for us. This commit doesn't fully replace GORM with SQLC, but introduces it for a few queries. Once all queries have been converted, GORM can be removed completely.
SQL Migrations
The files here are run by Goose, the database migration tool.
These are embedded into the Flamenco Manager executable, and automatically run on startup.
Foreign Key Constraints
Foreign Key constraints (FKCs) are optional in SQLite, and always enabled by
Flamenco Manager. These are temporarily disabled during database migration
itself. This means you can replace a table like this, without ON DELETE
effects running.
INSERT INTO `temp_table` SELECT * FROM `actual_table`;
DROP TABLE `actual_table`;
ALTER TABLE `temp_table` RENAME TO `actual_table`;