-- Fix: add updated_at column to tables that are missing it but have triggers
-- These fixes are for the LOCAL PostgreSQL database (vietprodev_sso)
-- Run these commands against the local PostgreSQL instance

-- 1. email_verify_tokens — add missing updated_at
ALTER TABLE email_verify_tokens ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();

-- Drop and recreate trigger to reference the column
DROP TRIGGER IF EXISTS update_email_verify_tokens_updated_at ON email_verify_tokens;
CREATE TRIGGER update_email_verify_tokens_updated_at
    BEFORE UPDATE ON email_verify_tokens
    FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();

COMMENT ON COLUMN email_verify_tokens.updated_at IS 'Auto-updated on every row change';
