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
21.47k stars 486 forks source link

[BUG]: Migrations not executed in order #2448

Open jsbrain opened 3 weeks ago

jsbrain commented 3 weeks ago

What version of drizzle-orm are you using?

0.31.0

What version of drizzle-kit are you using?

0.22.1

Describe the Bug

Migrations won't be executed in order on a new db.

I created a manual .sql file based on a pg_dump for the initial migration as we have some features that are not supported yet (e.g. enabling uuid-ossp extension) etc.

I then introspected the schema based on said initial dumped schema, which works fine. I can drop all tables and schemas, recreate the public schema and apply the migration file without issues.

Now when I make any change in the schema and run the npx drizzle-kit migrate again, it will work just fine and apply the 2nd migration.

But if I then try to delete the db, meaning dropping all tables and schemas and try to recreate the db with migrations, the operation will fail because it just runs the 2nd migration again without running the first one.

Note, that I dropped the drizzle schema as well so that cannot be the issue.

Expected behavior

On a fresh db without drizzle schema with migrations table it should run all migration files in correct order

Environment & setup

postgres v16

soamati commented 3 days ago

Hi, did you find a workaround for this?