Skip to content

fix(account): change social_id primary key in a single ALTER TABLE - #11153

Merged
ArtyomSavchenko merged 1 commit into
hcengineering:developfrom
MichaelUray:fix/cockroach-pk-migration
Oct 19, 2026
Merged

ArtyomSavchenko merged 1 commit into
hcengineering:developfrom
MichaelUray:fix/cockroach-pk-migration

Conversation

@MichaelUray

Copy link
Copy Markdown
Contributor

Fixes #9963

Problem and change

The account_db_v2_social_id_pk_change migration dropped the social_id
primary key and added the new one on _id in two separate ALTER TABLE
statements. CockroachDB v25.1+ commits DDL statements individually
(autocommit_before_ddl), so the drop is rejected with "primary key
dropped without subsequent addition of new primary key in same
transaction" and fresh installs cannot finish the account migrations.

Drop and add the constraint in one ALTER TABLE statement, which both
CockroachDB and PostgreSQL support with the same resulting schema.
Databases that already applied the migration are unaffected because
migrations are tracked by identifier; installs stuck on the failed
migration pick up the new DDL on the next retry.

Tests

New unit test server/account/src/__tests__/migrations.test.ts (the primary-key change is a single statement for Postgres and CockroachDB). The migration runner keys migrations by id, so databases that already applied it are unaffected; a database stuck on the failing statement retries with the new SQL.

The account_db_v2_social_id_pk_change migration dropped the social_id
primary key and added the new one on _id in two separate ALTER TABLE
statements. CockroachDB v25.1+ commits DDL statements individually
(autocommit_before_ddl), so the drop is rejected with "primary key
dropped without subsequent addition of new primary key in same
transaction" and fresh installs cannot finish the account migrations.

Drop and add the constraint in one ALTER TABLE statement, which both
CockroachDB and PostgreSQL support with the same resulting schema.
Databases that already applied the migration are unaffected because
migrations are tracked by identifier; installs stuck on the failed
migration pick up the new DDL on the next retry.

Fixes hcengineering#9963

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
@ArtyomSavchenko
ArtyomSavchenko merged commit 3110cd3 into hcengineering:develop Oct 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration Failure on v25+ of CockroachDB

2 participants