Files
windmill/backend/migrations/20260909085549_add_metrics_primary_key.up.sql
Ruben FiszelandClaude Opus 5 e62bfdcd8c fix: give every table a primary key so the db can be logically replicated (#11036)
* fix: give every table a primary key so the db can be logically replicated

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017WS9iNfYQiLJNuBnxysBzi

* fix: tighten replicability guard and trim migration comments

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017WS9iNfYQiLJNuBnxysBzi

* fix: split deployment_metadata into its own primary-key migration

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017WS9iNfYQiLJNuBnxysBzi

* docs: correct the partial-index predicate note after the deployment_metadata split

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017WS9iNfYQiLJNuBnxysBzi

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 18:42:24 +00:00

13 lines
641 B
SQL

-- The last of the seven; why any of them need a key is in
-- 20260909052532_add_missing_primary_keys.
--
-- Kept out of that migration because it is the largest (~400 MB / 750k rows on the
-- instance this was measured on, a steady state: `queue_%` rows, which are nearly all
-- of them, are swept at 14 days) and its ALTER rewrites it under ACCESS EXCLUSIVE. One
-- migration is one transaction, so alone it holds no lock on the others as it rewrites.
--
-- The surrogate cannot be called `id` -- `metrics.id` holds the metric NAME.
ALTER TABLE metrics
ADD COLUMN IF NOT EXISTS row_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;