Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/backend/drizzle/0008_migrate_messages_ciphertext.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Drop the full-text search index that relied on the plaintext content column.
DROP INDEX IF EXISTS "messages_content_search_idx";--> statement-breakpoint

-- Add the new nullable ciphertext column for single-blob E2EE messages.
ALTER TABLE "messages" ADD COLUMN "ciphertext" text;--> statement-breakpoint

-- Migrate existing plaintext content into ciphertext so no data is lost.
UPDATE "messages" SET "ciphertext" = "content" WHERE "deleted_at" IS NULL;--> statement-breakpoint

-- Drop the old plaintext content column.
ALTER TABLE "messages" DROP COLUMN "content";
2 changes: 1 addition & 1 deletion apps/backend/src/__tests__/conversations.cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ vi.mock('../db/schema.js', () => ({
id: 'id',
conversationId: 'conversationId',
senderId: 'senderId',
content: 'content',
ciphertext: 'ciphertext',
createdAt: 'createdAt',
deletedAt: 'deletedAt',
},
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/__tests__/conversations.routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vi.mock('../db/schema.js', () => ({
id: 'id',
conversationId: 'conversationId',
senderId: 'senderId',
content: 'content',
ciphertext: 'ciphertext',
createdAt: 'createdAt',
deletedAt: 'deletedAt',
},
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/src/__tests__/messages.routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ vi.mock('../db/schema.js', () => ({
id: 'id',
conversationId: 'conversationId',
senderId: 'senderId',
content: 'content',
ciphertext: 'ciphertext',
createdAt: 'createdAt',
deletedAt: 'deletedAt',
},
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('DELETE /messages/:id', () => {
id: 'msg-1',
conversationId: 'conv-1',
senderId: 'user-2',
content: 'hello',
ciphertext: 'hello',
deletedAt: null,
});

Expand All @@ -101,7 +101,7 @@ describe('DELETE /messages/:id', () => {
id: 'msg-1',
conversationId: 'conv-1',
senderId: 'user-1',
content: 'hello',
ciphertext: 'hello',
deletedAt: null,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/socket/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export function registerMessagingHandlers(io: Server, socket: AuthSocket): void
const response = await fetch('http://localhost:8000/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: content, conversation_id: conversationId }),
body: JSON.stringify({ message: ciphertext, conversation_id: conversationId }),
});

if (!response.ok) {
Expand Down
Loading