diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-16 15:06:30 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-16 15:06:30 -0400 |
| commit | 65ded7c0133ae011a30546fb4fd1e00fc3179874 (patch) | |
| tree | 305c9655c581ba5c959d56cf801a96bf80683dd7 /internal/models/migration.go | |
| parent | Update README (diff) | |
| download | cli-65ded7c0133ae011a30546fb4fd1e00fc3179874.zip | |
Update migration file format
Diffstat (limited to 'internal/models/migration.go')
| -rw-r--r-- | internal/models/migration.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/internal/models/migration.go b/internal/models/migration.go index b63fec9..ed48073 100644 --- a/internal/models/migration.go +++ b/internal/models/migration.go @@ -2,6 +2,7 @@ package models import ( "fmt" + "strings" "time" ) @@ -31,6 +32,16 @@ func NewSequentialMigration(version uint64, message string) *Migration { } } +// NormalizedMessage gives back the Message in lowercase, +// leading and trailing whitespace removed, and spaces +// replaced with underscores. +func (m Migration) NormalizedMessage() string { + message := strings.ToLower(m.Message) + message = strings.TrimSpace(message) + message = strings.ReplaceAll(message, " ", "_") + return message +} + func (m *Migration) Name() string { - return fmt.Sprintf("%s_%s", m.Version, m.Message) + return fmt.Sprintf("%s_%s", m.Version, m.NormalizedMessage()) } |