mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-08-05 16:49:17 +00:00

we remove all duplicate items from the registry, keeping the most-recently updated one (which presumably is the one that the users expect to be used) then we use `upsert` instead of the more complicated previous logic, which was subject to races
19 lines
709 B
JavaScript
19 lines
709 B
JavaScript
/*
|
|
* SPDX-FileCopyrightText: dakkar and other Sharkey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
export class RegistryUniqueConstraints1750591589187 {
|
|
async up(queryRunner) {
|
|
await queryRunner.query(`DELETE FROM "registry_item" WHERE "id" IN (
|
|
SELECT t."id" FROM (
|
|
SELECT *, ROW_NUMBER() OVER (PARTITION BY "userId","key","scope","domain" ORDER BY "updatedAt" DESC) rn
|
|
FROM "registry_item"
|
|
) t WHERE t.rn>1)`);
|
|
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_d9c48d580287308f8c1f674946" ON "registry_item" ("userId", "key", "scope", "domain") NULLS NOT DISTINCT`);
|
|
}
|
|
|
|
async down(queryRunner) {
|
|
await queryRunner.query(`DROP INDEX "public"."IDX_d9c48d580287308f8c1f674946"`);
|
|
}
|
|
}
|