CREATE TABLE user_activity_logs (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
    action VARCHAR(64) NOT NULL,
    title VARCHAR(255) NOT NULL DEFAULT '',
    detail TEXT,
    meta JSONB,
    ip_address VARCHAR(45),
    user_agent VARCHAR(512),
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_user_activity_logs_user_created ON user_activity_logs (user_id, created_at DESC);
CREATE INDEX idx_user_activity_logs_action ON user_activity_logs (action);
