Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Make more db relationships cascade on delete for charts #3828

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions db/migration/1722418726999-SuggestedRevisionsFkRelaxing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class SuggestedRevisionsFkRelaxing1722418726999
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
// 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<void> {
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;
`)
}
}
31 changes: 31 additions & 0 deletions db/migration/1722419367802-ChartDimensionsOnDeleteCascade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class ChartDimensionsOnDeleteCascade1722419367802
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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;
`)
}
}