mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
Fix active client session index
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class FixClientSessionActiveIndex1781320000000 implements MigrationInterface {
|
||||
public name = 'FixClientSessionActiveIndex1781320000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_unique_nonce"`);
|
||||
await queryRunner.query(`
|
||||
DELETE FROM "client_entity"
|
||||
WHERE ctid IN (
|
||||
SELECT ctid
|
||||
FROM (
|
||||
SELECT
|
||||
ctid,
|
||||
row_number() OVER (
|
||||
PARTITION BY "sessionId"
|
||||
ORDER BY "updatedAt" DESC, "createdAt" DESC, "id" DESC
|
||||
) AS rn
|
||||
FROM "client_entity"
|
||||
WHERE "deletedAt" IS NULL
|
||||
) duplicates
|
||||
WHERE rn > 1
|
||||
)
|
||||
`);
|
||||
await queryRunner.query(`
|
||||
CREATE UNIQUE INDEX "IDX_unique_nonce"
|
||||
ON "client_entity" ("sessionId")
|
||||
WHERE "deletedAt" IS NULL
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_unique_nonce"`);
|
||||
await queryRunner.query(`
|
||||
CREATE UNIQUE INDEX "IDX_unique_nonce"
|
||||
ON "client_entity" ("sessionId")
|
||||
WHERE "deletedAt" IS NULL
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user