drizzle-team / drizzle-team/drizzle-orm
[BUG]: Drizzle kit applies multiple migration files in the same transaction
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
?
### What version of `drizzle-kit` are you using?
?
### Describe the Bug
From drizzle-kit-mirror repo: https://github.com/drizzle-team/drizzle-kit-mirror/issues/522.
> If you have two separate migrations that haven't been deployed yet, drizzle-kit runs both the migrations as part of the same transaction. This results in unwanted behaviour where a developer might have applied migration 1 then generated migration 2 and applied it and on deployment, both the migrations are run together.
>
> **Previous state:** `my_table` has a column `type` of enum `my_type` with default `value`
>
> **Goal:** Add `new_value` to the `my_type` enum and set it as default for column `type` on `my_table`
>
> **Migration 1:**
>
> ```sql
> ALTER TYPE "my_type" ADD VALUE 'new_value';
> ```
>
> **Migration 2:**
>
> ```sql
> ALTER TABLE my_table ALTER COLUMN "type" SET DEFAULT 'new_value'
> ```
>
> **Expected behaviour:** Each migration is committed separately.
>
> **Actual behaviour:**
>
> ```
> PostgresError: unsafe use of new value "new_value" of enum type "my_type"
> ```
>
> **Present hack applied to resolve the issue:** Added following lines to start of migration 2.
>
> ```
> COMMIT; -- Commit already present transaction
> BEGIN; -- Begin new transaction
> ```
Possibly related: https://github.com/drizzle-team/drizzle-kit-mirror/issues/525
> If I have one schema that creates some table, and another later schema that alters the table, trying to drizzle-kit migrate will fail with the error: PostgresError: cannot ALTER TABLE "tablename" because it has pending trigger events
>
> This is a common problem for tooling that doesn't commit each schema file separately, so I would assume drizzle-kit has this problem too, although the source is apparently not available to read?
### Expected behavior
_No response_
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.