2016-05-24 11:55:48 +02:00
|
|
|
package db
|
2016-01-05 00:32:53 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2016-03-16 22:49:43 +01:00
|
|
|
|
|
|
|
"github.com/ansible-semaphore/semaphore/util"
|
2016-01-05 00:32:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type DBVersion struct {
|
|
|
|
Major int
|
|
|
|
Minor int
|
|
|
|
Patch int
|
|
|
|
Build string
|
|
|
|
|
|
|
|
UpgradedDate *time.Time
|
|
|
|
Notes *string
|
|
|
|
}
|
|
|
|
|
|
|
|
var Versions []*DBVersion
|
|
|
|
var initialSQL = `
|
|
|
|
create table ` + "`migrations`" + ` (
|
|
|
|
` + "`version`" + ` varchar(255) not null primary key,
|
|
|
|
` + "`upgraded_date`" + ` datetime null,
|
|
|
|
` + "`notes`" + ` text null
|
|
|
|
) engine=innodb charset=utf8;
|
|
|
|
`
|
|
|
|
|
|
|
|
func (version *DBVersion) VersionString() string {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
func (version *DBVersion) HumanoidVersion() string {
|
|
|
|
return "v" + version.VersionString()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (version *DBVersion) GetPath() string {
|
2016-05-24 11:55:48 +02:00
|
|
|
return "db/migrations/v" + version.VersionString() + ".sql"
|
2016-01-05 00:32:53 +01:00
|
|
|
}
|
|
|
|
func (version *DBVersion) GetErrPath() string {
|
2016-05-24 11:55:48 +02:00
|
|
|
return "db/migrations/v" + version.VersionString() + ".err.sql"
|
2016-01-05 00:32:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (version *DBVersion) GetSQL(path string) []string {
|
|
|
|
sql := util.MustAsset(path)
|
|
|
|
return strings.Split(string(sql), ";\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Versions = []*DBVersion{
|
|
|
|
{},
|
2016-04-08 21:41:20 +02:00
|
|
|
{Major: 1},
|
2016-04-09 00:51:24 +02:00
|
|
|
{Major: 1, Minor: 1},
|
2016-04-11 12:02:10 +02:00
|
|
|
{Major: 1, Minor: 2},
|
|
|
|
{Major: 1, Minor: 3},
|
2016-04-16 21:42:57 +02:00
|
|
|
{Major: 1, Minor: 4},
|
2016-04-30 14:28:47 +02:00
|
|
|
{Major: 1, Minor: 5},
|
2016-05-21 01:47:09 +02:00
|
|
|
{Minor: 1},
|
2016-06-17 22:16:46 +02:00
|
|
|
{Major: 1, Minor: 6},
|
2016-06-26 00:43:59 +02:00
|
|
|
{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},
|
2017-03-12 19:51:03 +01:00
|
|
|
{Major: 2, Minor: 2, Patch: 1},
|
2017-03-10 01:12:55 +01:00
|
|
|
{Major: 2, Minor: 3},
|
2016-01-05 00:32:53 +01:00
|
|
|
}
|
|
|
|
}
|