Semaphore/db/Migration.go

104 lines
2.2 KiB
Go
Raw Normal View History

package db
import (
"fmt"
"time"
)
// Migration represents sql schema version
type Migration struct {
Version string `db:"version" json:"version"`
UpgradedDate *time.Time `db:"upgraded_date" json:"upgraded_date"`
Notes *string `db:"notes" json:"notes"`
}
// HumanoidVersion adds a v to the VersionString
func (m Migration) HumanoidVersion() string {
return "v" + m.Version
}
func GetMigrations() []Migration {
return []Migration{
2022-01-23 17:34:42 +01:00
{Version: "0.0.0"},
{Version: "1.0.0"},
{Version: "1.2.0"},
{Version: "1.3.0"},
{Version: "1.4.0"},
{Version: "1.5.0"},
{Version: "1.6.0"},
{Version: "1.7.0"},
{Version: "1.8.0"},
{Version: "1.9.0"},
{Version: "2.2.1"},
{Version: "2.3.0"},
{Version: "2.3.1"},
{Version: "2.3.2"},
{Version: "2.4.0"},
{Version: "2.5.0"},
{Version: "2.5.2"},
{Version: "2.7.1"},
{Version: "2.7.4"},
{Version: "2.7.6"},
{Version: "2.7.8"},
{Version: "2.7.9"},
{Version: "2.7.10"},
{Version: "2.7.12"},
{Version: "2.7.13"},
{Version: "2.8.0"},
{Version: "2.8.1"},
{Version: "2.8.7"},
{Version: "2.8.8"},
{Version: "2.8.20"},
{Version: "2.8.25"},
{Version: "2.8.26"},
{Version: "2.8.36"},
2022-01-31 22:30:36 +01:00
{Version: "2.8.38"},
{Version: "2.8.39"},
2022-02-03 08:05:13 +01:00
{Version: "2.8.40"},
{Version: "2.8.42"},
{Version: "2.8.51"},
{Version: "2.8.57"},
2022-10-28 16:59:50 +02:00
{Version: "2.8.58"},
{Version: "2.8.91"},
{Version: "2.9.6"},
{Version: "2.9.46"},
2024-02-11 21:24:53 +01:00
{Version: "2.9.60"},
2024-03-06 22:17:34 +01:00
{Version: "2.9.61"},
2024-03-07 19:50:48 +01:00
{Version: "2.9.62"},
{Version: "2.9.70"},
{Version: "2.9.97"},
{Version: "2.9.100"},
{Version: "2.10.12"},
{Version: "2.10.15"},
{Version: "2.10.16"},
}
}
func Migrate(d Store) error {
didRun := false
for _, version := range GetMigrations() {
if exists, err := d.IsMigrationApplied(version); err != nil || exists {
if exists {
continue
}
return err
}
didRun = true
fmt.Printf("Executing migration %s (at %v)...\n", version.HumanoidVersion(), time.Now())
if err := d.ApplyMigration(version); err != nil {
fmt.Printf("Rolling back %s (time: %v)...\n", version.HumanoidVersion(), time.Now())
d.TryRollbackMigration(version)
return err
}
}
if didRun {
fmt.Println("Migrations Finished")
}
return nil
}