summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-25 00:16:16 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-28 21:31:40 -0400
commitc0ead9cf11471a07d0906d90fcbe1d17b09862f5 (patch)
tree2b4596f06af2e9bcdf87d83e674029401e644d4d
parentregister instances before creating a user (diff)
downloadsharkey-c0ead9cf11471a07d0906d90fcbe1d17b09862f5.tar.gz
sharkey-c0ead9cf11471a07d0906d90fcbe1d17b09862f5.tar.bz2
sharkey-c0ead9cf11471a07d0906d90fcbe1d17b09862f5.zip
remove broken HTTP users before running add_instance_foreign_keys migration
-rw-r--r--packages/backend/migration/1748128176881-add_instance_foreign_keys.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/packages/backend/migration/1748128176881-add_instance_foreign_keys.js b/packages/backend/migration/1748128176881-add_instance_foreign_keys.js
index da2de14f18..9a970699a0 100644
--- a/packages/backend/migration/1748128176881-add_instance_foreign_keys.js
+++ b/packages/backend/migration/1748128176881-add_instance_foreign_keys.js
@@ -15,6 +15,11 @@ 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")`);
+
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`);
await queryRunner.query(`ALTER TABLE "note" ADD CONSTRAINT "FK_note_replyUserHost" FOREIGN KEY ("replyUserHost") REFERENCES "instance"("host") ON DELETE CASCADE ON UPDATE NO ACTION`);