Files
decomp.dev/migrations/20_cascade_delete_reports.sql
Luke Street 76d390f073 Fix report deletion
Resolves #12
2025-09-12 23:26:08 -06:00

28 lines
899 B
SQL

PRAGMA foreign_keys = off;
ALTER TABLE report_report_units
RENAME TO report_report_units_old;
CREATE TABLE report_report_units
(
report_id INTEGER NOT NULL,
report_unit_id BLOB NOT NULL,
unit_index INTEGER NOT NULL, -- Index of the report unit in the report
PRIMARY KEY (report_id, report_unit_id, unit_index),
FOREIGN KEY (report_id) REFERENCES reports (id) ON DELETE CASCADE,
FOREIGN KEY (report_unit_id) REFERENCES report_units (id)
);
DROP INDEX report_report_units_report_id_index;
DROP INDEX report_report_units_report_unit_id_index;
CREATE INDEX report_report_units_report_id_index ON report_report_units (report_id);
CREATE INDEX report_report_units_report_unit_id_index ON report_report_units (report_unit_id);
INSERT INTO report_report_units
SELECT *
FROM report_report_units_old;
DROP TABLE report_report_units_old;
PRAGMA foreign_keys = on;