From 44ff1abd747068861f95a18cef0adf75ebf5b66a Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Tue, 23 Apr 2024 01:49:26 +0200 Subject: [PATCH] Update 20240405000045_org-memberships-unique-constraint.ts --- .../20240405000045_org-memberships-unique-constraint.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/db/migrations/20240405000045_org-memberships-unique-constraint.ts b/backend/src/db/migrations/20240405000045_org-memberships-unique-constraint.ts index 9a342d542..1743c7524 100644 --- a/backend/src/db/migrations/20240405000045_org-memberships-unique-constraint.ts +++ b/backend/src/db/migrations/20240405000045_org-memberships-unique-constraint.ts @@ -42,6 +42,7 @@ export async function up(knex: Knex): Promise { await knex.transaction(async (tx) => { const duplicateRows = await tx(TableName.OrgMembership) .select("userId", "orgId") // Select the userId and orgId so we can group by them + .whereNotNull("userId") // Ensure that the userId is not null .count("* as cnt") // Count the number of rows for each userId and orgId, so we can make sure there are more than 1 row (a duplicate) .groupBy("userId", "orgId") .havingRaw("count(*) > ?", [1]); // Using havingRaw for direct SQL expressions @@ -97,6 +98,8 @@ export async function up(knex: Knex): Promise { `Deleted ${numberOfRowsDeleted} duplicate organization memberships for ${row.userId} and ${row.orgId}` ); } + + throw new Error("This is a test error"); }); await knex.schema.alterTable(TableName.OrgMembership, (table) => {