mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-11 17:16:50 -05:00
fix(migration): add cleanup step for duplicate push subscriptions before enforcing unique constraint (#2269)
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
@@ -6,6 +6,15 @@ export class AddUniqueConstraintToPushSubscription1765233385034
|
|||||||
name = 'AddUniqueConstraintToPushSubscription1765233385034';
|
name = 'AddUniqueConstraintToPushSubscription1765233385034';
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DELETE FROM "user_push_subscription"
|
||||||
|
WHERE id NOT IN (
|
||||||
|
SELECT MAX(id)
|
||||||
|
FROM "user_push_subscription"
|
||||||
|
GROUP BY "endpoint", "userId"
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "user_push_subscription" ADD CONSTRAINT "UQ_6427d07d9a171a3a1ab87480005" UNIQUE ("endpoint", "userId")`
|
`ALTER TABLE "user_push_subscription" ADD CONSTRAINT "UQ_6427d07d9a171a3a1ab87480005" UNIQUE ("endpoint", "userId")`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,15 @@ export class AddUniqueConstraintToPushSubscription1765233385034
|
|||||||
name = 'AddUniqueConstraintToPushSubscription1765233385034';
|
name = 'AddUniqueConstraintToPushSubscription1765233385034';
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DELETE FROM "user_push_subscription"
|
||||||
|
WHERE id NOT IN (
|
||||||
|
SELECT MAX(id)
|
||||||
|
FROM "user_push_subscription"
|
||||||
|
GROUP BY "endpoint", "userId"
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE UNIQUE INDEX "UQ_6427d07d9a171a3a1ab87480005" ON "user_push_subscription" ("endpoint", "userId")`
|
`CREATE UNIQUE INDEX "UQ_6427d07d9a171a3a1ab87480005" ON "user_push_subscription" ("endpoint", "userId")`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user