Avoiding conflicts with database migrations

When the database schema is modified, a migration script must be written into a vXXX.go file in the migrations directory of the models package. When the corresponding pull request requires discussions that last during weeks (which is likely because the database modifications are carefully reviewed), the odds that another pull request is merged and conflicts is high. The vXXX.go file has to be renamed which painful. To avoid this, it is possible to do the following.

var migrations = append(gitea_migrations, []Migration{
	NewMigration("Add Index field to comments", addCommentIndex),
}...)

var gitea_migrations = []Migration{
	// Gitea 1.5.0 ends at v69
  • Name the file v1000.go or anything that is unlikely to be used any time soon

I find it a little odd that Gitea have chosen the vXXX format. SQL migrations manager like sqlx(rust) and yoyo-migrations(python) all use dates to order migrations.

Contents of ForgeFlux Interface DB migrations

➜  interface git:(init-interface) ✗ tree -L 1 migrations
migrations
├── 20211023_01_0W52q-event-subscriptions.py
├── 20211024_01_h2IuD-interface-jobs.py
├── 20211223_01_pFC7s-interface-forks.py
├── 20211226_01_zx3oY-forge-data.py
├── 20220102_01_q4rHE-events.py
├── 20220116_01_Ur7VF-activities.py
└── __pycache__
1 Like