mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
## What Migrations `0098`–`0100` undo migration `0097` (community artifact expand). The declared schema goes back to its shape before #9650. #9650 added `0097`. The revert, #9689, removed the feature but kept `0097` byte for byte, because databases that auto-migrated recorded its checksum. No code on `main` reads or writes what `0097` added. This PR removes it with forward migrations, as `docs/database.md` requires ("Never edit a merged migration. Fix forward."). `artifact_heads.channel_id` gets `NOT NULL` back in the three steps from *Adding `NOT NULL` to a populated table*: - `0098` checks that the artifact head key is `(community_id, artifact_id)`, then adds `CHECK (channel_id IS NOT NULL) NOT VALID`. - `0099` validates the check under `SHARE UPDATE EXCLUSIVE`, so channel artifact reads and writes continue. - `0100` sets `NOT NULL` from the validated check (no scan), drops the check, drops `artifact_heads_live_type`, `artifact_heads_scoped_identity` and `artifact_revisions_scoped_identity`, and drops `artifact_heads.scope`, `artifact_revisions.scope`, `artifact_revisions.community_event`, `artifact_revisions.redacted` and `communities.artifact_type_policies`. The primary keys don't change. `0097` never changed them. ## Review checklist (docs/database.md) - **Phase:** contract. It follows the expand in #9650 (`0097`) and the code revert in #9689. - **Required stop:** every relay pod, job and rollback target must run #9689 (`sha-a406191`) or later before `0100` runs. The chart's upgrade notes (`deploy/charts/buzz/README.md`) say this, along with how to roll back with auto-migration off. No tagged relay release contains #9650. Only rolling images from `eebf62b6` up to, but not including, `a4061916` are affected. Relays built from #9650 itself read `artifact_heads.scope` and write with `ON CONFLICT` on `artifact_heads_scoped_identity`. Releases before #9650 never read these objects. - **Fails closed:** `0098` refuses a database whose artifact head key is the scoped key from #9650's removed operator contract script or declared schema. That database needs the recovery in #9689's Compatibility section. `0099` fails if any head has a null `channel_id`. Both stop before any cleanup. - No trigger, function, procedure, rule or foreign key is added. No migration changes existing rows. - Every schema location in Rule 4 is updated: `migrations/` and `schema/tables/public/` (`artifact_heads.sql`, `artifact_revisions.sql`, `communities.sql`). No reconcile-script or gateway change applies. - **Currently deployed relay:** a relay from #9689 or later doesn't use these objects, and neither does a relay from before #9650. The populated-table test runs every migration over channel artifact data. - **Locks:** each migration sets `lock_timeout = '5s'` and `statement_timeout = '30s'`. No index is built. ## Tests - `admin_schema_parity_between_desired_state_and_migrations` compares `artifact_heads`, `artifact_revisions` and `communities` across the desired-state and migrated paths. It fails without `0100`. - `populated_artifact_tables_auto_migrate_through_every_migration` checks that a channel head and revision written before `0097` survive with the same channel and event. - `artifact_unexpand_validates_while_channel_heads_are_written`: `0099` completes while a channel head write is still open. It fails if `0099` sets `NOT NULL` directly. - `artifact_unexpand_refuses_scoped_head_key`: `0098` stops on the scoped key and leaves `0097`'s columns in place. ## What got simpler The schema loses 5 unused columns and 3 unused indexes. `artifact_heads.channel_id` is required again, as the channel code assumes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Luke Tornquist <tornquist@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
918 B
SQL
24 lines
918 B
SQL
-- Undo 0097, step 3 of 3. Requires every relay pod and job to run #9689 or a
|
|
-- later release (see 0098).
|
|
--
|
|
-- SET NOT NULL uses the check validated in 0099 and skips the table scan. The
|
|
-- drops are catalog-only. Each statement takes ACCESS EXCLUSIVE on its table;
|
|
-- fail the deployment rather than queue relay reads and writes behind a long
|
|
-- holder.
|
|
SET LOCAL lock_timeout = '5s';
|
|
SET LOCAL statement_timeout = '30s';
|
|
|
|
ALTER TABLE artifact_heads ALTER COLUMN channel_id SET NOT NULL;
|
|
ALTER TABLE artifact_heads DROP CONSTRAINT artifact_heads_channel_id_not_null;
|
|
|
|
DROP INDEX artifact_heads_live_type;
|
|
DROP INDEX artifact_heads_scoped_identity;
|
|
DROP INDEX artifact_revisions_scoped_identity;
|
|
|
|
ALTER TABLE artifact_heads DROP COLUMN scope;
|
|
ALTER TABLE artifact_revisions
|
|
DROP COLUMN scope,
|
|
DROP COLUMN community_event,
|
|
DROP COLUMN redacted;
|
|
ALTER TABLE communities DROP COLUMN artifact_type_policies;
|