jackc / tern

The SQL Fan's Migrator
MIT License
850 stars 66 forks source link

Dependency-based or git-based conflict resolution #82

Closed NanoBjorn closed 1 year ago

NanoBjorn commented 1 year ago

Became a bit annoyed with constant conflicts in a relatively big project 😄

I have a proposal to cover some cases, share your thoughts on it.

In sql it is pretty easy to understand dependent tables from parsing the query (I am sure there are some golang parsers for postgres sql), so maybe tern can auto-resolve conflicts when migrations do not intersect over table? Or this may have dangerous hidden mistakes? For sure it is not covering all the cases, but just a thought.

Another thing is it may be useful to have a separate command with conflict resolution and different strategy. Another strategy that I came up with is git-based — if there are duplicates and one file is already committed, then let's automatically increase the number for the second one? you still check what is being committed before commit so it should not be dangerous

jackc commented 1 year ago

In sql it is pretty easy to understand dependent tables from parsing the query (I am sure there are some golang parsers for postgres sql), so maybe tern can auto-resolve conflicts when migrations do not intersect over table? Or this may have dangerous hidden mistakes? For sure it is not covering all the cases, but just a thought.

I think there would be too many edge cases for this to be handled automatically.

Another thing is it may be useful to have a separate command with conflict resolution and different strategy. Another strategy that I came up with is git-based — if there are duplicates and one file is already committed, then let's automatically increase the number for the second one? you still check what is being committed before commit so it should not be dangerous

It's not automatic but there already is a command to do something like this. See https://github.com/jackc/tern#renumbering-conflicting-migrations.

NanoBjorn commented 1 year ago

Got it, thansk!