mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
f3076ed418
* 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>
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
"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
|
|
`);
|
|
},
|
|
};
|