Files
wehub-resource-sync b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:23:53 +08:00

36 lines
2.0 KiB
SQL

-- Add `indexed_at` to the four content tables that the read API exposes via
-- the `packageView` / `releaseView` lexicon shapes.
--
-- Why a separate column from `verified_at`: `verified_at` tracks "when the
-- aggregator last verified this record", and is bumped on every upsert
-- (including no-op re-verifications). The read API needs "when the aggregator
-- first observed this record" so the lexicon's `indexedAt` field is stable
-- across re-ingest. They diverge whenever a record is re-fetched (e.g.
-- backfill catching up on a record we already had via Jetstream).
--
-- Defaulting to `verified_at` for any rows that pre-date this migration: the
-- closest approximation we can make for already-indexed content. Going
-- forward, the consumer's INSERTs set `indexed_at` to `now()` on first write
-- and COALESCE the existing value on conflict (see records-consumer.ts).
--
-- NOT NULL after backfill from `verified_at`. SQLite's `ALTER TABLE` doesn't
-- support DEFAULT-with-NOT-NULL in one step, so we add the column nullable,
-- backfill, then move the constraint via the new-table dance — except SQLite
-- also can't add NOT NULL via ALTER, so we keep the column nullable at the
-- schema level and have the writer (consumer) treat it as required. The
-- read-API code defends against NULL by falling back to verified_at if
-- indexed_at is somehow missing on a row, which won't happen for new writes
-- but covers the historical-data corner case without a table rebuild.
ALTER TABLE packages ADD COLUMN indexed_at TEXT;
UPDATE packages SET indexed_at = verified_at WHERE indexed_at IS NULL;
ALTER TABLE releases ADD COLUMN indexed_at TEXT;
UPDATE releases SET indexed_at = verified_at WHERE indexed_at IS NULL;
ALTER TABLE publishers ADD COLUMN indexed_at TEXT;
UPDATE publishers SET indexed_at = verified_at WHERE indexed_at IS NULL;
ALTER TABLE publisher_verifications ADD COLUMN indexed_at TEXT;
UPDATE publisher_verifications SET indexed_at = verified_at WHERE indexed_at IS NULL;