From 6ccf7fedbbde3c5bb2950fe41921cbdbe371fc2d Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:54:07 +0100 Subject: [PATCH] fix(federation): stop destructive dm_messages migration from re-running on every deploy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SQLite stores self-referencing FK identifiers with quotes (REFERENCES "dm_messages"), but the migration guard only checked for the unquoted string. This caused the migration to re-run on every server startup, which DROP TABLE dm_messages and triggered ON DELETE CASCADE on attachments.dm_message_id — wiping every DM-linked attachment. --- packages/server/src/db/migrate.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/db/migrate.ts b/packages/server/src/db/migrate.ts index 74515561..22dd05d0 100644 --- a/packages/server/src/db/migrate.ts +++ b/packages/server/src/db/migrate.ts @@ -612,7 +612,7 @@ function migrateDmMessagesReplyToFk(db: Database.Database): void { // Only migrate if reply_to_id exists but has no FK reference if (!tableInfo) return; if (!tableInfo.sql.includes('reply_to_id')) return; - if (tableInfo.sql.includes('REFERENCES dm_messages')) return; + if (tableInfo.sql.includes('REFERENCES dm_messages') || tableInfo.sql.includes('REFERENCES "dm_messages"')) return; console.log('Migrating: Adding FK constraint to dm_messages.reply_to_id...'); @@ -1279,7 +1279,7 @@ function migrateAttachmentsDmMessageFk(db: Database.Database): void { // Only migrate if dm_message_id exists but has no FK reference if (!tableInfo) return; if (!tableInfo.sql.includes('dm_message_id')) return; - if (tableInfo.sql.includes('REFERENCES dm_messages')) return; + if (tableInfo.sql.includes('REFERENCES dm_messages') || tableInfo.sql.includes('REFERENCES "dm_messages"')) return; console.log('Migrating: Adding FK constraint to attachments.dm_message_id...');