fix(federation): stop destructive dm_messages migration from re-running on every deploy

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.
This commit is contained in:
Jannis Braun
2026-03-26 17:54:07 +01:00
parent f362f5530c
commit 6ccf7fedbb
+2 -2
View File
@@ -612,7 +612,7 @@ function migrateDmMessagesReplyToFk(db: Database.Database): void {
// Only migrate if reply_to_id exists but has no FK reference // Only migrate if reply_to_id exists but has no FK reference
if (!tableInfo) return; if (!tableInfo) return;
if (!tableInfo.sql.includes('reply_to_id')) 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...'); 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 // Only migrate if dm_message_id exists but has no FK reference
if (!tableInfo) return; if (!tableInfo) return;
if (!tableInfo.sql.includes('dm_message_id')) 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...'); console.log('Migrating: Adding FK constraint to attachments.dm_message_id...');