diff --git a/db/migration/1722418726999-SuggestedRevisionsFkRelaxing.ts b/db/migration/1722418726999-SuggestedRevisionsFkRelaxing.ts new file mode 100644 index 00000000000..a277357c47f --- /dev/null +++ b/db/migration/1722418726999-SuggestedRevisionsFkRelaxing.ts @@ -0,0 +1,77 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class SuggestedRevisionsFkRelaxing1722418726999 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + // Change: ON DELETE RESTRICT -> ON DELETE CASCADE + // + // This means that if a chart or user is deleted, then any + // linked suggested revisions are deleted too. + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_1 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_1 + FOREIGN KEY (chartId) REFERENCES charts(id) + ON DELETE CASCADE ON UPDATE RESTRICT; + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_2 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_2 + FOREIGN KEY (createdBy) REFERENCES users(id) + ON DELETE CASCADE ON UPDATE RESTRICT; + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_3 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_3 + FOREIGN KEY (updatedBy) + REFERENCES users(id) + ON DELETE CASCADE ON UPDATE RESTRICT; + `) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_1 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_1 + FOREIGN KEY (chartId) REFERENCES charts(id) + ON DELETE RESTRICT ON UPDATE RESTRICT; + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_2 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_2 + FOREIGN KEY (createdBy) REFERENCES users(id) + ON DELETE RESTRICT ON UPDATE RESTRICT; + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + DROP FOREIGN KEY suggested_chart_revisions_ibfk_3 + `) + await queryRunner.query(`-- sql + ALTER TABLE suggested_chart_revisions + ADD CONSTRAINT suggested_chart_revisions_ibfk_3 + FOREIGN KEY (updatedBy) + REFERENCES users(id) + ON DELETE RESTRICT ON UPDATE RESTRICT; + `) + } +} diff --git a/db/migration/1722419367802-ChartDimensionsOnDeleteCascade.ts b/db/migration/1722419367802-ChartDimensionsOnDeleteCascade.ts new file mode 100644 index 00000000000..71cd7369ffc --- /dev/null +++ b/db/migration/1722419367802-ChartDimensionsOnDeleteCascade.ts @@ -0,0 +1,31 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class ChartDimensionsOnDeleteCascade1722419367802 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`-- sql + ALTER TABLE chart_dimensions + DROP FOREIGN KEY chart_dimensions_chartId_78d6a092_fk_charts_id + `) + await queryRunner.query(`-- sql + ALTER TABLE chart_dimensions + ADD CONSTRAINT chart_dimensions_chartId_78d6a092_fk_charts_id + FOREIGN KEY (chartId) REFERENCES charts(id) + ON DELETE CASCADE ON UPDATE RESTRICT; + `) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`-- sql + ALTER TABLE chart_dimensions + DROP FOREIGN KEY chart_dimensions_chartId_78d6a092_fk_charts_id + `) + await queryRunner.query(`-- sql + ALTER TABLE chart_dimensions + ADD CONSTRAINT chart_dimensions_chartId_78d6a092_fk_charts_id + FOREIGN KEY (chartId) REFERENCES charts(id) + ON DELETE RESTRICT ON UPDATE RESTRICT; + `) + } +}