Skip to content

Commit

Permalink
Merge pull request #1719 from Infisical/daniel/migration-fix
Browse files Browse the repository at this point in the history
Fix: Duplicate org membership migration
  • Loading branch information
maidul98 authored Apr 22, 2024
2 parents 08cb105 + 233a4f7 commit 1ba7a31
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function up(knex: Knex): Promise<void> {
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
Expand Down

0 comments on commit 1ba7a31

Please sign in to comment.