Skip to content

[BUG]: Drizzle kit applies multiple migration files in the same transaction #3249

Description

@L-Mario564

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:

ALTER TYPE "my_type" ADD VALUE 'new_value';

Migration 2:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdrizzle/kitpriorityWill be worked on next

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions