mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
Fix shares_collectionId_fkey constraint error with CASCADE delete (#10196)
* Fix foreign key constraint error for shares.collectionId - Add migration to update shares_collectionId_fkey constraint with CASCADE delete - This fixes the constraint violation when deleting collections that have associated shares - Follows the same pattern as the existing shares_documentId_fkey cascade fix Fixes #10185 * Simplify migration by removing unnecessary loop and constraint array - Remove loop and constraintNames array since there's only one constraint - Directly reference 'shares_collectionId_fkey' constraint name - Keep the same functionality but with cleaner, simpler code --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// Drop the existing foreign key constraint
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE "shares" DROP CONSTRAINT "shares_collectionId_fkey"`
|
||||
);
|
||||
|
||||
// Add the foreign key constraint with CASCADE delete
|
||||
await queryInterface.sequelize.query(`
|
||||
ALTER TABLE "shares"
|
||||
ADD CONSTRAINT "shares_collectionId_fkey"
|
||||
FOREIGN KEY("collectionId")
|
||||
REFERENCES "collections" ("id")
|
||||
ON DELETE CASCADE
|
||||
`);
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
// Drop the cascade constraint
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE "shares" DROP CONSTRAINT "shares_collectionId_fkey"`
|
||||
);
|
||||
|
||||
// Add back the original constraint without cascade
|
||||
await queryInterface.sequelize.query(`
|
||||
ALTER TABLE "shares"
|
||||
ADD CONSTRAINT "shares_collectionId_fkey"
|
||||
FOREIGN KEY("collectionId")
|
||||
REFERENCES "collections" ("id")
|
||||
ON DELETE NO ACTION
|
||||
`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user