rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.16k stars 269 forks source link

How to distinguish the different branches #264

Closed wxy2077 closed 3 months ago

wxy2077 commented 3 months ago

a1.sql

B branch migrate sql: b1.sql

dev-mysql: dialect: mysql datasource: root:123456@tcp(127.0.0.1:3306)/example?parseTime=true dir: migrate/mysql table: migrations


If I migrate branch A and then switch to branch B, and execute the migration statement `sql-migrate up -env=dev-mysql` ,I get an error.

Migration failed: Unable to create migration plan because of a1.sql: unknown migration in database



Because the migration statement 'a1.sql' is already in 'table:migrations'

- My suggestions

My idea is to add a branch field to the migration table and distinguish branches when migrating.
rubenv commented 3 months ago

That really is an anti-pattern what you're doing there. You're building a potentially inconsistent history of migrations.

Merge A into B before migrating. That way branch B will have both a1.sql and b1.sql.

wxy2077 commented 3 months ago

Because my colleagues and I are developing different tasks synchronously, but using the same test db, the online time of the

tasks is different, although they will be merged into the master branch eventually, but in the development process, if the

colleague's branch has not been tested, I cannot merge his branch, which leads to the problem of SQL migration.

rubenv commented 3 months ago

You're all using the same database server to test your changes against? Isn't that a source of constant conflicts?

wxy2077 commented 3 months ago

Well, then we have to change the database. Thank you for your reply.