create table if not exists campus_documents ( id bigserial primary key, source_name text not null default '绵阳城市学院教务处', source_type text not null default 'official_website', category text, title text not null, department text not null default '教务处', publish_date date, source_url text not null unique, content text, content_hash text not null, attachments jsonb not null default '[]'::jsonb, status text not null default 'active', last_checked_at timestamptz not null default now(), created_at timestamptz not null default now(), updated_at timestamptz not null default now() ); create index if not exists idx_campus_documents_publish_date on campus_documents (publish_date desc); create index if not exists idx_campus_documents_category on campus_documents (category); create index if not exists idx_campus_documents_search on campus_documents using gin ( to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(content, '')) ); create table if not exists sync_runs ( id bigserial primary key, started_at timestamptz not null default now(), finished_at timestamptz, status text not null default 'running', scanned_count integer not null default 0, upserted_count integer not null default 0, error text );