Skip to content

MNTOR-4499: subscriber id foreign key cascade for feature_flag_events #5886

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex) {
await knex.schema.alterTable("feature_flag_events", (table) => {
// Drop the existing foreign key constraint
table.dropForeign(
["created_by_subscriber_id"],
"feature_flag_events_created_by_subscriber_id_foreign",
);

// Add the new foreign key constraint with ON UPDATE CASCADE and ON DELETE CASCADE
// Explicitly naming the new constraint is good practice.
table
.foreign(
"created_by_subscriber_id",
"feature_flag_events_created_by_subscriber_id_fk_cascade",
)
.references("id")
.inTable("subscribers")
.onUpdate("CASCADE")
.onDelete("CASCADE");
});
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex) {
await knex.schema.alterTable("feature_flag_events", (table) => {
// Drop the CASCADE foreign key constraint
table.dropForeign(
["created_by_subscriber_id"],
"feature_flag_events_created_by_subscriber_id_fk_cascade",
);

// Re-add the original foreign key constraint (defaulting to RESTRICT/NO ACTION)
// Ensuring the original constraint name is used.
table
.foreign(
"created_by_subscriber_id",
"feature_flag_events_created_by_subscriber_id_foreign",
)
.references("id")
.inTable("subscribers");
});
}
Loading