1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/migrations/20220808110415-add-projects-foreign-key.js
sjaanus 59b8a06968
Deleting project does not delete entry group_role table (#1896)
* Add constraint for project

* Add constraint for project

* Add constraint for project

* Add constraint for project

* Add constraint for project

* Revert eslint

* Fix eslint

* Fix tests
2022-08-10 07:45:59 +00:00

21 lines
510 B
JavaScript

exports.up = function (db, cb) {
db.runSql(
`
delete from group_role where project not in (select id from projects);
ALTER TABLE group_role
ADD CONSTRAINT fk_group_role_project
FOREIGN KEY(project)
REFERENCES projects(id) ON DELETE CASCADE; `,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
ALTER TABLE group_role DROP CONSTRAINT fk_group_role_project;
`,
cb,
);
};