diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 07:46:23 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 07:46:23 -0400 |
| commit | 53ec45482d6424964bdaf767e15b16623dc69661 (patch) | |
| tree | 7cff89931f76f2ffe90d3c7fe12e6c0d51341a1b /packages/backend/migration | |
| parent | fix tests (diff) | |
| download | sharkey-53ec45482d6424964bdaf767e15b16623dc69661.tar.gz sharkey-53ec45482d6424964bdaf767e15b16623dc69661.tar.bz2 sharkey-53ec45482d6424964bdaf767e15b16623dc69661.zip | |
use more robust fixup in 1748128176881-add_instance_foreign_keys.js
Diffstat (limited to 'packages/backend/migration')
| -rw-r--r-- | packages/backend/migration/1748128176881-add_instance_foreign_keys.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/packages/backend/migration/1748128176881-add_instance_foreign_keys.js b/packages/backend/migration/1748128176881-add_instance_foreign_keys.js index 9a970699a0..2c2383c50f 100644 --- a/packages/backend/migration/1748128176881-add_instance_foreign_keys.js +++ b/packages/backend/migration/1748128176881-add_instance_foreign_keys.js @@ -15,10 +15,19 @@ export class AddInstanceForeignKeys1748128176881 { name = 'AddInstanceForeignKeys1748128176881' async up(queryRunner) { - // Fix-up: Sharkey versions in early-mid 2025 could federate with HTTP URLs, which would produce a user with no matching instance. - // These users are fundamentally broken and can just be removed, which ensures that the FK can create without conflicts. - // But we must also *preserve* those with a matching registered instance, as FireFish allowed federation over HTTP and some older instances may have fully-populated users. - await queryRunner.query(`DELETE FROM "user" WHERE "uri" LIKE 'http:%' AND NOT EXISTS (select 1 from "instance" where "instance"."host" = "user"."host")`); + // Fix-up: Some older instances have users without a matching instance entry + await queryRunner.query(` + INSERT INTO "instance" ("id", "host", "firstRetrievedAt") + SELECT + MIN("id"), + "host", + COALESCE(MIN("lastFetchedAt"), CURRENT_TIMESTAMP) + FROM "user" + WHERE + "host" IS NOT NULL AND + NOT EXISTS (select 1 from "instance" where "instance"."host" = "user"."host") + GROUP BY "host" + `); await queryRunner.query(`ALTER TABLE "user" ADD CONSTRAINT "FK_user_host" FOREIGN KEY ("host") REFERENCES "instance"("host") ON DELETE CASCADE ON UPDATE NO ACTION`); await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_note_userHost" FOREIGN KEY ("userHost") REFERENCES "instance"("host") ON DELETE CASCADE ON UPDATE NO ACTION`); |