From bc346a69c43961e1478ed3acfd80c24d566394bf Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 1 Jan 2024 20:23:56 -0500 Subject: Add migration tests --- internal/models/migration.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'internal/models/migration.go') diff --git a/internal/models/migration.go b/internal/models/migration.go index a19b95f..c02f17a 100644 --- a/internal/models/migration.go +++ b/internal/models/migration.go @@ -3,7 +3,8 @@ package models import ( "fmt" "strings" - "time" + + "github.com/eugenetriguba/bolt/internal/util" ) type Migration struct { @@ -12,8 +13,8 @@ type Migration struct { Applied bool } -func NewMigration(message string) *Migration { - now := time.Now() +func NewMigration(clock util.Clock, message string) *Migration { + now := clock.Now() version := fmt.Sprintf( "%d%02d%02d%02d%02d%02d", now.Year(), now.Month(), now.Day(), @@ -27,11 +28,9 @@ func (m *Migration) Dirname() string { } func (m *Migration) normalizedMessage() string { - return strings.ReplaceAll( - strings.TrimSpace(strings.ToLower(m.Message)), - " ", - "_", - ) + lowercaseMessage := strings.ToLower(m.Message) + trimmedMessage := strings.TrimSpace(lowercaseMessage) + return strings.ReplaceAll(trimmedMessage, " ", "_") } func (m *Migration) String() string { @@ -40,10 +39,15 @@ func (m *Migration) String() string { checked = "x" } + message := m.normalizedMessage() + if len(message) > 0 { + message = fmt.Sprintf("- %s ", message) + } + return fmt.Sprintf( - "%s - %s - [%s]", + "%s %s- [%s]", m.Version, - m.normalizedMessage(), + message, checked, ) } -- cgit v1.2.3