CREATE TABLE IF NOT EXISTS reporting_saved_views (
    id SERIAL PRIMARY KEY,
    owner_user VARCHAR(128) NOT NULL,
    owner_role VARCHAR(32) NULL,
    view_id VARCHAR(64) NOT NULL,
    name VARCHAR(160) NOT NULL,
    snapshot_json TEXT NOT NULL DEFAULT '{}',
    created_at VARCHAR(64) NOT NULL,
    updated_at VARCHAR(64) NOT NULL,
    CONSTRAINT uq_reporting_saved_views_owner_view UNIQUE (owner_user, view_id)
);

CREATE INDEX IF NOT EXISTS idx_reporting_saved_views_owner_updated
ON reporting_saved_views (owner_user, updated_at);
