Skip to content

feat(db): write one ship event per CMS send, and note a draft published again (00425) - #1883

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w2-20-db
Oct 31, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-w2-20-db

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Migration 00425 for the impact ledger (00421, CHAT-22 §2). The W2-20 code PR is stacked on this one. Please apply 00425 on prod before deploying that code. It adds two nullable columns, so the code already on prod is unaffected.

Why: when a CMS confirms a sent page is live, the server writes a ship event. That confirmation can arrive more than once, from the webhook's callback and from a status poll, or from two servers at the same moment. Each extra confirmation would be a second shipped change on the same prompts. Two measurements on the same targets then make each other Not measurable (overlapping_change).

00425

  • ship_events.content_draft_delivery_id uuid:
    • the send (content_draft_deliveries) this ship event is the publish of; FK on delete set null; null for every other kind of ship event;
    • ship_events_content_draft_delivery_uidx is a plain unique index, not a partial one. PostgREST's on_conflict names columns only, and Postgres can't infer a partial index without its predicate. Nulls stay distinct, so ship events without a send never collide.
    • The server writes with an upsert that ignores a second write (on conflict do nothing).
  • ship_events.republished_at timestamptz: the last time the same draft went live again within 90 days. No second ship event is written then; the first measurement goes on.
  • The migration is idempotent (if not exists). It has no RLS or grant changes; ship_events keeps 00421's policies.
  • supabase/schema.sql was rebuilt with build-schema.sh. web/src/types/supabase.ts and web/src/lib/chat/schema.test.ts are updated.

Related issue

None. Chat Wave 2 (W2-20, CHAT-22 §2).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Apply 00425_ship_events_delivery.sql. Re-running it changes nothing.
  2. Insert a ship_events row for a send with on conflict (content_draft_delivery_id) do nothing, twice. The first returns 1 row, the second 0.
  3. Run bash supabase/build-schema.sh. schema.sql doesn't change.

Applied on the dev database. I ran step 2 inside a transaction and rolled it back: first 1, second 0, one row for the send.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

On the W2-20 tip (this commit + the stacked code): web format:check and typecheck pass, lint has 0 errors (7 old warnings in files this PR doesn't touch), and schema.test.ts passes (44 tests). build-schema.sh leaves schema.sql unchanged.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 31, 2026
gkhngyk
gkhngyk previously approved these changes Oct 31, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One ship event per CMS send, backed by a unique index per delivery, and a draft published again is noted on it. Apply 00425 before merging.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.

@gkhngyk
gkhngyk merged commit fba125d into ansvisor:main Oct 31, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants