dukcapil/migrations/000020_update_letter_outgoing_recipients.up.sql
2025-08-29 16:10:05 +07:00

14 lines
956 B
SQL

-- Add missing fields to letter_outgoing_recipients table to match incoming letter structure
ALTER TABLE letter_outgoing_recipients
ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES users(id),
ADD COLUMN IF NOT EXISTS department_id UUID REFERENCES departments(id),
ADD COLUMN IF NOT EXISTS status TEXT DEFAULT 'pending',
ADD COLUMN IF NOT EXISTS read_at TIMESTAMP WITHOUT TIME ZONE,
ADD COLUMN IF NOT EXISTS flag TEXT,
ADD COLUMN IF NOT EXISTS is_archived BOOLEAN DEFAULT false;
-- Add indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_recipients_user ON letter_outgoing_recipients(user_id);
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_recipients_department ON letter_outgoing_recipients(department_id);
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_recipients_status ON letter_outgoing_recipients(status);
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_recipients_archived ON letter_outgoing_recipients(is_archived);