Skip to content

Commit 38f2b64

Browse files
authored
fix: migration unique check (#3754)
1 parent 7519f93 commit 38f2b64

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

bin/migrateKratosUsers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const migratePasswordAccounts = async (
155155
const { rowCount } = await dailyPool.query(
156156
`INSERT INTO ba_account (id, "userId", "providerId", "accountId", password, "createdAt", "updatedAt")
157157
VALUES ${placeholders.join(', ')}
158-
ON CONFLICT (id) DO NOTHING`,
158+
ON CONFLICT ("userId", "providerId") DO NOTHING`,
159159
values,
160160
);
161161
total += rowCount ?? 0;
@@ -229,7 +229,7 @@ const migrateOidcAccounts = async (
229229
const { rowCount } = await dailyPool.query(
230230
`INSERT INTO ba_account (id, "userId", "providerId", "accountId", "createdAt", "updatedAt")
231231
VALUES ${placeholders.join(', ')}
232-
ON CONFLICT (id) DO NOTHING`,
232+
ON CONFLICT ("userId", "providerId") DO NOTHING`,
233233
values,
234234
);
235235
total += rowCount ?? 0;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class BaAccountUserProviderUnique1774400000000 implements MigrationInterface {
4+
name = 'BaAccountUserProviderUnique1774400000000';
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(/* sql */ `
8+
CREATE UNIQUE INDEX IF NOT EXISTS
9+
"IDX_ba_account_userId_providerId"
10+
ON "ba_account" ("userId", "providerId")
11+
`);
12+
}
13+
14+
public async down(queryRunner: QueryRunner): Promise<void> {
15+
await queryRunner.query(/* sql */ `
16+
DROP INDEX IF EXISTS "IDX_ba_account_userId_providerId"
17+
`);
18+
}
19+
}

0 commit comments

Comments
 (0)