aboutsummaryrefslogtreecommitdiffstats
path: root/internal/models/migration.go
blob: b63fec91e226b389c473f5ff3fccefdaddb29045 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package models

import (
	"fmt"
	"time"
)

type Migration struct {
	Version string
	Message string
	Applied bool
}

func NewTimestampMigration(version time.Time, message string) *Migration {
	return &Migration{
		Version: fmt.Sprintf(
			"%d%02d%02d%02d%02d%02d",
			version.Year(), version.Month(), version.Day(),
			version.Hour(), version.Minute(), version.Second(),
		),
		Message: message,
		Applied: false,
	}
}

func NewSequentialMigration(version uint64, message string) *Migration {
	return &Migration{
		Version: fmt.Sprintf("%03d", version),
		Message: message,
		Applied: false,
	}
}

func (m *Migration) Name() string {
	return fmt.Sprintf("%s_%s", m.Version, m.Message)
}