"""Baseline flags on extracted entities + trigram search indexes. Entities captured by a sensor's very first snapshot are not "new" — they existed before we started observing (coverage normalisation, spec §145). `baseline = true` lets metrics, daily aggregates and job summaries count only entities that appeared *after* observation started, without touching first_seen_at (which stays the honest observation timestamp). Revision ID: 0002 Revises: 0001 """ from __future__ import annotations from alembic import op revision = "0002" down_revision = "0001" branch_labels = None depends_on = None SQL = """ alter table jobs add column if not exists baseline boolean not null default false; alter table people add column if not exists baseline boolean not null default false; alter table products add column if not exists baseline boolean not null default false; alter table locations add column if not exists baseline boolean not null default false; alter table news_items add column if not exists baseline boolean not null default false; alter table pricing_plans add column if not exists baseline boolean not null default false; create index if not exists jobs_new_idx on jobs (company_id, first_seen_at desc) where not baseline; create index if not exists news_items_new_idx on news_items (company_id, first_seen_at desc) where not baseline; create index if not exists people_name_trgm_idx on people using gin (name gin_trgm_ops); create index if not exists products_name_trgm_idx on products using gin (name gin_trgm_ops); """ def upgrade() -> None: for stmt in [s.strip() for s in SQL.split(";") if s.strip()]: op.execute(stmt) def downgrade() -> None: raise RuntimeError("forward-only migrations")