BEGIN;

-- Add revision_number to letter_outgoing_attachments
ALTER TABLE letter_outgoing_attachments 
ADD COLUMN IF NOT EXISTS revision_number INTEGER NOT NULL DEFAULT 0;

-- Add revision_number to letter_outgoing_approvals
ALTER TABLE letter_outgoing_approvals 
ADD COLUMN IF NOT EXISTS revision_number INTEGER NOT NULL DEFAULT 0;

-- Create indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_attachments_revision ON letter_outgoing_attachments(letter_id, revision_number);
CREATE INDEX IF NOT EXISTS idx_letter_outgoing_approvals_revision ON letter_outgoing_approvals(letter_id, revision_number);

COMMIT;