rubenv / sql-migrate

SQL schema migration tool for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to distinguish the different branches

wxy2077 opened this issue · comments

  • Question:
    When different branches have different migration statements, an error will be reported when migrating at the same time.

  • Example:

A branch migrate sql:

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.

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.

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.

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

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