drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
290 stars 16 forks source link

`drizzle-kit generate` should not add random words to migration filename. #483

Open gburtini opened 1 month ago

gburtini commented 1 month ago

When you generate a migration, three files are modified:

  1. a new SQL file, called {ID}_{two or three random words}.sql, which describes the transformations to synchronize the database with the current state of the schema.
  2. a snapshot file, called meta/{ID}_snapshot.json
  3. and the journal file, listing off the migrations in order.

When two developers in separate branches create migrations simultaneously, files (2) and (3) will correctly result in conflicts, but file (1) will not. This means simple patterns like merge --theirs && regenerate leave behind an additional file (here is an example script to do that that may be instructive for someone who wants to do this on their team).

The random word pattern used in many other ORMs makes sense, because migrations are not monotonically incrementing IDs. With Drizzle, two migrations created simultaneously share an ID and may reference the wrong snapshot, so they necessarily must be manually resolved.

Obviously I would invite other solutions for dealing with conflicts. Merge queues, timestamp-as-ID or a smart resolve tool may be a better solution.

hprathap commented 3 weeks ago

+1 for this