prisma-engines icon indicating copy to clipboard operation
prisma-engines copied to clipboard

Remove cockroach shadow db transaction

Open GustavoEdinger opened this issue 2 months ago • 2 comments

This pull request removes the special handling for CockroachDB when applying the migrations to the shadow db as it breaks under certain conditions, and it's against the recommendation from CockroachDB.

I understand that this reverts https://github.com/prisma/prisma-engines/pull/5138, which was intended to speed up migrate dev. Unfortunately, it breaks when the migrations in the project have the following steps:

--- Migration file 1
CREATE TYPE "Color" AS ENUM ('Black', 'White');

--- Migration file 2
ALTER TYPE "Color" ADD VALUE 'Red';

---  Migration file 3
ALTER TABLE "MyTable" ADD COLUMN     "selected_color" "Color" NOT NULL DEFAULT 'Red';

The change in the type it's only avaialable after the it's committed due to cockroach limitations.

Here's an example of the error:

Error: P3006

Migration `20250225160003_migration_3` failed to apply cleanly to the shadow database. 
Error:
ERROR: invalid input value for enum Color: "Red"
   0: schema_core::state::DevDiagnostic
             at schema-engine/core/src/state.rs:294

As stated in the documentation running inside a transaction is not supported by the database. https://www.cockroachlabs.com/docs/stable/online-schema-changes

The workaround suggested by the documentation would be to set SET autocommit_before_ddl = on; which would auto commit the schema changes inside a transaction but that's only available from cockroachdb 24.1. Meaning prisma would have to set a min db version. https://www.cockroachlabs.com/docs/v24.1/online-schema-changes#enable-automatic-commit-before-running-schema-changes-inside-transactions

/test-all

GustavoEdinger avatar Oct 28 '25 11:10 GustavoEdinger

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 28 '25 11:10 CLAassistant

CodSpeed Performance Report

Merging #5669 will not alter performance

Comparing GustavoEdinger:fix/cockroach-shadowdb-transaction (fb2f69e) with main (08761dd)

Summary

✅ 11 untouched

codspeed-hq[bot] avatar Oct 30 '25 14:10 codspeed-hq[bot]