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:
codegen-sh[bot]
2025-09-17 08:57:16 -04:00
committed by GitHub
parent 70321350d4
commit f3076ed418
@@ -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
`);
},
};