-- Import previews are immutable snapshots; applying one is an explicit admin action. CREATE TABLE IF NOT EXISTS schedule_imports ( id UUID PRIMARY KEY, route_id INTEGER REFERENCES routes(id) ON DELETE SET NULL, source_url TEXT NOT NULL, source_hash TEXT NOT NULL, source JSONB NOT NULL, status TEXT NOT NULL CHECK (status IN ('inspection', 'ready', 'applied')), payload JSONB, created_by INTEGER, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), applied_at TIMESTAMPTZ ); CREATE INDEX IF NOT EXISTS idx_schedule_imports_created ON schedule_imports(created_at DESC); CREATE TABLE IF NOT EXISTS schedule_import_news ( url TEXT PRIMARY KEY, title TEXT NOT NULL, published_date TEXT, content TEXT NOT NULL, content_hash TEXT NOT NULL, reviewed_hash TEXT, checked_at TIMESTAMPTZ NOT NULL DEFAULT now() );