From 30b51567007222cb4403c6d6fbdbf5edb6e65760 Mon Sep 17 00:00:00 2001 From: Jeremy Alvis Date: Tue, 5 May 2026 07:30:32 -0700 Subject: [PATCH] Fix feedback primary key for upgrades from below 0.7.14 Signed-off-by: Jeremy Alvis --- .../core/000004_feedback_single_pk.down.sql | 9 +++++++++ .../core/000004_feedback_single_pk.up.sql | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 go/core/pkg/migrations/core/000004_feedback_single_pk.down.sql create mode 100644 go/core/pkg/migrations/core/000004_feedback_single_pk.up.sql diff --git a/go/core/pkg/migrations/core/000004_feedback_single_pk.down.sql b/go/core/pkg/migrations/core/000004_feedback_single_pk.down.sql new file mode 100644 index 000000000..b868a277d --- /dev/null +++ b/go/core/pkg/migrations/core/000004_feedback_single_pk.down.sql @@ -0,0 +1,9 @@ +-- No-op: 000004 is a corrective convergence step. Both fresh installs (which +-- already had PRIMARY KEY (id) from 000001) and upgraded installs (which +-- carried the legacy composite PRIMARY KEY (id, user_id) from GORM +-- AutoMigrate) end at PRIMARY KEY (id). Once up has run, there is no way to +-- tell which path the database came from, so a symmetric down would put fresh +-- installs into a composite-PK state they never originally had. Leaving the +-- single-column PK in place on rollback is safer and the application is +-- PK-shape independent (queries do not reference the PK directly). +SELECT 1; diff --git a/go/core/pkg/migrations/core/000004_feedback_single_pk.up.sql b/go/core/pkg/migrations/core/000004_feedback_single_pk.up.sql new file mode 100644 index 000000000..9a5033d53 --- /dev/null +++ b/go/core/pkg/migrations/core/000004_feedback_single_pk.up.sql @@ -0,0 +1,13 @@ +-- Normalize the feedback primary key to (id) only. +-- +-- Fresh installs from 000001 already have PRIMARY KEY (id) (BIGSERIAL). +-- Installs that upgraded from the GORM-managed schema retained the legacy +-- composite PRIMARY KEY (id, user_id) created by AutoMigrate. +-- +-- Both variants use the default constraint name `feedback_pkey`, so this +-- atomic drop+add converges both paths to the single-column PK without +-- changing column types or affecting sqlc-generated code (queries do not +-- reference the PK; ListFeedback filters on user_id via idx_feedback_user_id). +ALTER TABLE feedback + DROP CONSTRAINT feedback_pkey, + ADD CONSTRAINT feedback_pkey PRIMARY KEY (id);