Rustelo/resources/user-dashboard/migrations/007_message_status_sqlite.sql
Jesús Pérez f1010e9d07
chore: update
2026-07-18 20:16:16 +01:00

17 lines
668 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Migration: 007 Enhance user_messages with status lifecycle and timestamps
-- Database: SQLite
--
-- SQLite does not support ADD COLUMN with constraints referencing other columns
-- or backfill in a single ALTER, so we do it in two steps.
ALTER TABLE user_messages ADD COLUMN status TEXT NOT NULL DEFAULT 'sent';
ALTER TABLE user_messages ADD COLUMN received_at DATETIME;
ALTER TABLE user_messages ADD COLUMN deleted_at DATETIME;
-- Backfill already-read rows.
UPDATE user_messages
SET status = 'read',
received_at = created_at
WHERE is_read = 1;
CREATE INDEX IF NOT EXISTS idx_user_messages_status ON user_messages(user_id, status);