drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.37k stars 635 forks source link

[BUG]: drizzle-kit push unexpected behaviour #2322

Open jsbrain opened 6 months ago

jsbrain commented 6 months ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.2

Describe the Bug

I introspected a schema that has some features that are currently not supported by drizzle, e.g. sequences, extensions.

Drizzle does introspect the schema to the most extend and generates a uncomplete 0000-xxxx.sql file.

To mitigate the issue I replace the contents of the initial file with the data from the .sql schema file generated via pg_dump --schema-only.

This now successfully initializes the db with the proper schema and all required features so I can use drizzle migrations for our project with the drizzle-kit migrate command.

The drizzle-kit push command on the other hand virtually recreates the initially incomplete .sql file generated by the introspection command and executes this, completely ignoring the .sql file I manually edited.

Is this expected behaviour?

I also noticed that in some cases, it seems as if drizzle-kit push even tries to execute old migration data, I ran into this after I made changes on the db and introspected again (bascially completely deleted the drizzle directory and started over) and it would still give me the sql commands generated for the previous introspected schema.

Expected behavior

drizzle-kit push forcefully executes all migrations in sequence, ignoring the drizzle migrations history, respecting the .sql migration files and executing the commands of said files

Environment & setup

No response

jsbrain commented 6 months ago

I might be wrong in my assumptions about how this command works but it seems very odd that it tries to regenerate the commands or tries to execute stale data...