2020-12-01 20:06:49 +01:00
|
|
|
package sql
|
2016-01-05 00:32:53 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// Versions holds all sql schema version references
|
|
|
|
var Versions []*Version
|
2016-01-05 00:32:53 +01:00
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// 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)
|
|
|
|
}
|
2018-03-27 22:12:47 +02:00
|
|
|
|
|
|
|
// HumanoidVersion adds a v to the VersionString
|
|
|
|
func (version *Version) HumanoidVersion() string {
|
2016-01-05 00:32:53 +01:00
|
|
|
return "v" + version.VersionString()
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// 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
|
|
|
}
|
2018-03-27 22:12:47 +02: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
|
|
|
}
|
|
|
|
|
2018-03-27 22:12:47 +02: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 {
|
2018-03-05 19:59:58 +01:00
|
|
|
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() {
|
2018-03-27 22:12:47 +02:00
|
|
|
Versions = []*Version{
|
2016-01-05 00:32:53 +01:00
|
|
|
{},
|
2016-04-08 21:41:20 +02:00
|
|
|
{Major: 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-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},
|
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},
|
2017-05-03 06:27:58 +02:00
|
|
|
{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},
|
2021-05-13 15:49:32 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 1},
|
2021-08-20 08:28:50 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 4},
|
2021-08-26 10:01:42 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 6},
|
2021-08-30 16:24:20 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 8},
|
2021-08-30 21:42:11 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 9},
|
2021-08-31 07:47:19 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 10},
|
2021-09-01 21:17:28 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 12},
|
2021-09-06 13:05:10 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 13},
|
2021-09-16 23:20:59 +02:00
|
|
|
{Major: 2, Minor: 7, Patch: 17},
|
2021-10-11 23:36:35 +02:00
|
|
|
{Major: 2, Minor: 8, Patch: 0},
|
2016-01-05 00:32:53 +01:00
|
|
|
}
|
|
|
|
}
|