Semaphore/db/version.go

88 lines
2.0 KiB
Go
Raw Normal View History

2016-05-24 11:55:48 +02:00
package db
2016-01-05 00:32:53 +01:00
import (
"fmt"
"strings"
"time"
)
// Version represents an sql schema version
type Version struct {
2016-01-05 00:32:53 +01:00
Major int
Minor int
Patch int
Build string
UpgradedDate *time.Time
Notes *string
}
// Versions holds all sql schema version references
var Versions []*Version
2016-01-05 00:32:53 +01:00
var initialSQL = `
create table ` + "`migrations`" + ` (
` + "`version`" + ` varchar(255) not null primary key,
` + "`upgraded_date`" + ` datetime null,
` + "`notes`" + ` text null
) engine=innodb charset=utf8;
`
// VersionString returns a well formatted string of the current Version
func (version *Version) VersionString() string {
2016-01-05 00:32:53 +01:00
s := fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch)
if len(version.Build) == 0 {
return s
}
return fmt.Sprintf("%s-%s", s, version.Build)
}
// HumanoidVersion adds a v to the VersionString
func (version *Version) HumanoidVersion() string {
2016-01-05 00:32:53 +01:00
return "v" + version.VersionString()
}
// GetPath is the humanoid version with the file format appended
func (version *Version) GetPath() string {
return version.HumanoidVersion() + ".sql"
2016-01-05 00:32:53 +01:00
}
//GetErrPath is the humanoid version with '.err' and file format appended
func (version *Version) GetErrPath() string {
return version.HumanoidVersion() + ".err.sql"
2016-01-05 00:32:53 +01:00
}
// GetSQL takes a path to an SQL file and returns it from packr as a slice of strings separated by newlines
func (version *Version) GetSQL(path string) []string {
sql, err := dbAssets.MustString(path)
if err != nil {
panic(err)
}
return strings.Split(sql, ";\n")
2016-01-05 00:32:53 +01:00
}
func init() {
Versions = []*Version{
2016-01-05 00:32:53 +01:00
{},
{Major: 1},
2016-04-09 00:51:24 +02:00
{Major: 1, Minor: 1},
{Major: 1, Minor: 2},
{Major: 1, Minor: 3},
{Major: 1, Minor: 4},
{Major: 1, Minor: 5},
2016-05-21 01:47:09 +02:00
{Minor: 1},
{Major: 1, Minor: 6},
{Major: 1, Minor: 7},
2016-06-30 16:57:45 +02:00
{Major: 1, Minor: 8},
2016-11-22 02:18:44 +01:00
{Major: 1, Minor: 9},
{Major: 2, Minor: 2, Patch: 1},
{Major: 2, Minor: 3},
2017-04-18 18:21:10 +02:00
{Major: 2, Minor: 3, Patch: 1},
2017-04-18 18:25:59 +02:00
{Major: 2, Minor: 3, Patch: 2},
{Major: 2, Minor: 4},
2018-02-17 00:46:23 +01:00
{Major: 2, Minor: 5},
2018-10-15 17:48:19 +02:00
{Major: 2, Minor: 5, Patch: 2},
2016-01-05 00:32:53 +01:00
}
}