CREATE TABLE IF NOT EXISTS reporting_saved_views (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    owner_user TEXT NOT NULL,
    owner_role TEXT NULL,
    view_id TEXT NOT NULL,
    name TEXT NOT NULL,
    snapshot_json TEXT NOT NULL DEFAULT '{}',
    created_at TEXT NOT NULL,
    updated_at TEXT 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);
