Auth#1
Conversation
Review Summary by QodoRefine initial database schema and migrations
WalkthroughsDescription• Refined database schema with improved comments and structure • Made public_key optional for future E2EE implementation • Added soft delete support to messages table • Cleaned up migration file with clearer table documentation Diagramflowchart LR
users["users table<br/>with optional public_key"]
chats["chats table<br/>for conversations"]
participants["chat_participants<br/>many-to-many"]
messages["messages table<br/>with soft delete"]
indexes["performance indexes"]
users -- "references" --> participants
chats -- "references" --> participants
chats -- "references" --> messages
users -- "references" --> messages
messages -- "indexed by" --> indexes
File Changes1. migrations/20250521102510_initial_schema.sql
|
Code Review by Qodo
1.
|
| nonce BLOB NOT NULL, -- 12 bytes unique per message | ||
| tag BLOB NOT NULL, -- 16 bytes authentication tag | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')) | ||
| sender_id TEXT NOT NULL REFERENCES users(id) ON DELETE SET NULL, |
There was a problem hiding this comment.
1. Invalid fk delete action 🐞 Bug ≡ Correctness
messages.sender_id is declared NOT NULL but uses ON DELETE SET NULL, so deleting a referenced users row will fail with a constraint error when foreign keys are enforced. This makes user hard-deletes unreliable and the FK action effectively incorrect.
Agent Prompt
### Issue description
`messages.sender_id` is `NOT NULL` while the FK specifies `ON DELETE SET NULL`. SQLite will attempt to set `sender_id` to NULL on user deletion, which violates `NOT NULL` and aborts the delete.
### Issue Context
Foreign key enforcement is enabled in the application’s SQLite connection options, so this will surface as a runtime failure.
### Fix Focus Areas
- migrations/20260521102510_initial_schema.sql[28-37]
- src/db/mod.rs[4-8]
### Suggested fix
Pick one consistent behavior:
- If you want to preserve messages when a user is deleted: make `sender_id` nullable (remove `NOT NULL`) and keep `ON DELETE SET NULL`.
- If you never want user deletion to orphan messages: keep `NOT NULL` and change the FK action to `ON DELETE RESTRICT`/`NO ACTION` (or `CASCADE` if appropriate).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
No description provided.