why do snapshots not have the same name as the migrations?
Hey, loving dirzzle so far.
Hit a snag recently. Me and my friend are collaborating on a project. We ended up in a merge conflict. Here is what happened:
1. We both created our separate branches from main.
2. He created migrations and ran the migration script to make the changes to his local db.
2. I created migrations and ran the migration script to make changes to my local db.
3. He merged his branch to main.
4. I merge main into my local branch. I see the merge conflicts as attached.
What my diagnosis is:
1. When he created the migration (unique name prefixed with 0007_) and ran it, it created 0007snapshot in his branch.
2. When I created the migration (another unique name prefixed with 0007) and ran it, it created 0007_snapshot in my branch.
There is a merge conflict in spoke too soon, I cant even fix the conflict in _journal.json as well but I think that is expected.
"Why is the snapshot's name not the same as migration so as to avoid conflicts?"
The only way I can think of solving this conflict is to manually merge and it will be erroneous for sure because it wont signify the db state at the 0007 index for either of us.
PS: I am familiar with Rails migrations, and am expecting a similar approach.
7 Replies
spoke too soon, I cant even fix the conflict in _journal.json without deleting either of the SQL migration files
Do you have a PR open or are this changes local?
What I've seen, and I'm not sure this is the best approach, is when people notice a merge confilct with the magrations:
1.- Merge from main, notice a merge conflict with the migrations
2.- Revert the merge and drop the local migration
3.- Merge again and resolve possible conflicts in the schema file
4.- Create and run new migration with all the changes
5.- Create new PR to merge into main
These are local changes. While what you suggested would work, I'm not sure if this is the optimal dx.
I ended up manually merging the conflicts and running
drizzle-kit push:pg
any reasons why snapshots' name does not match migration name?
i think it would work just fine if dirzzle used same name for snapshots and migrations. Maybe copy rails with the timestamp based naming for better sort (the suffixes for migrations might already be sortable based on the time they were created but i have not checked that).Let's ping @Andrew Sherman for some insights
The problem with the push command is that your migration might drift from your schema definition. Then the DB state might not be reproducible with the migrations. You could do it manually if you know what you're doing.
@angelelz suggested a right way to do it. If you have pulled some migrations that were not in your local - you need to accept all incoming changes while resolving conflicts(or just drop your migrations)
After that generate a new migration
That's the only right way to do it
after that I would also suggest to run
drizzle-kit check
it will check if snapshots and journal state is in the right order
and you don't have 2 conflicting migrations after mergeAlright makes sense. Thanks for the prompt response.
Would something like albemic sqlalchemy (merging branches) [https://alembic.sqlalchemy.org/en/latest/branches.html#merging-branches] solve this issue? Is there a reason there isn't a way like this to do it automatically?