diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-02 11:07:30 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-02 11:07:30 -0500 |
| commit | 571bc9bf2efa841b29bf036f4d307664bfbe155d (patch) | |
| tree | 41fb3a459db99d1f0ec2ed2e00d4ca580a5d0c46 /internal/models/migration.go | |
| parent | Update readme (diff) | |
| parent | Remove Latest() from migration fs repo in favor of using List on service (diff) | |
| download | cli-571bc9bf2efa841b29bf036f4d307664bfbe155d.zip | |
Merge pull request #1 from eugenetriguba/0.3.0
Diffstat (limited to 'internal/models/migration.go')
| -rw-r--r-- | internal/models/migration.go | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/internal/models/migration.go b/internal/models/migration.go index f647a1b..b63fec9 100644 --- a/internal/models/migration.go +++ b/internal/models/migration.go @@ -11,30 +11,26 @@ type Migration struct { Applied bool } -func NewMigration(timestamp time.Time, message string) *Migration { - version := fmt.Sprintf( - "%d%02d%02d%02d%02d%02d", - timestamp.Year(), timestamp.Month(), timestamp.Day(), - timestamp.Hour(), timestamp.Minute(), timestamp.Second(), - ) - return &Migration{Version: version, Message: message, Applied: false} -} - -func (m *Migration) String() string { - checkmark := " " - if m.Applied { - checkmark = "x" +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, } +} - message := m.Message - if len(message) > 0 { - message = fmt.Sprintf("- %s ", message) +func NewSequentialMigration(version uint64, message string) *Migration { + return &Migration{ + Version: fmt.Sprintf("%03d", version), + Message: message, + Applied: false, } +} - return fmt.Sprintf( - "%s %s- [%s]", - m.Version, - message, - checkmark, - ) +func (m *Migration) Name() string { + return fmt.Sprintf("%s_%s", m.Version, m.Message) } |