diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 16:23:02 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 16:23:02 -0500 |
| commit | 263ce3e4b368a50efee1a53af11a76a12af0a119 (patch) | |
| tree | 8917754f3b43830604f6ad4c7115934ed633f1d8 /internal/models/migration.go | |
| parent | Fix syntax (diff) | |
| download | cli-263ce3e4b368a50efee1a53af11a76a12af0a119.zip | |
Break up migration repo into fs and db with a service
Diffstat (limited to 'internal/models/migration.go')
| -rw-r--r-- | internal/models/migration.go | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/internal/models/migration.go b/internal/models/migration.go index a4b694c..a449c44 100644 --- a/internal/models/migration.go +++ b/internal/models/migration.go @@ -12,19 +12,16 @@ type Migration struct { Applied bool } -func NewMigration(ts time.Time, message string) *Migration { +func NewMigration(timestamp time.Time, message string) *Migration { version := fmt.Sprintf( - "%d%02d%02d%02d%02d%02d", ts.Year(), ts.Month(), ts.Day(), - ts.Hour(), ts.Minute(), ts.Second(), + "%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) Dirname() string { - return fmt.Sprintf("%s_%s", m.Version, m.normalizedMessage()) -} - -func (m *Migration) normalizedMessage() string { +func (m *Migration) NormalizedMessage() string { lowercaseMessage := strings.ToLower(m.Message) trimmedMessage := strings.TrimSpace(lowercaseMessage) return strings.ReplaceAll(trimmedMessage, " ", "_") @@ -36,7 +33,7 @@ func (m *Migration) String() string { checked = "x" } - message := m.normalizedMessage() + message := m.NormalizedMessage() if len(message) > 0 { message = fmt.Sprintf("- %s ", message) } |