aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-11-13 22:20:16 -0800
committerEugene Triguba <hello@eugenetriguba.com>2026-11-13 22:20:16 -0800
commit7026e3861a5712ced6f2006f282c8386b4db106e (patch)
tree18db906e76c1736a831f345b4832db91964c960a /internal
parentRemove timestamp version style in favor of always using sequential (diff)
downloadcli-7026e3861a5712ced6f2006f282c8386b4db106e.zip
Pad new migrations to 4 digits
Diffstat (limited to 'internal')
-rw-r--r--internal/models/migration.go2
-rw-r--r--internal/models/migration_test.go8
-rw-r--r--internal/repositories/migration_fs_repo_test.go2
-rw-r--r--internal/services/migration_test.go100
4 files changed, 56 insertions, 56 deletions
diff --git a/internal/models/migration.go b/internal/models/migration.go
index 44608f9..74a1536 100644
--- a/internal/models/migration.go
+++ b/internal/models/migration.go
@@ -13,7 +13,7 @@ type Migration struct {
func NewMigration(version uint64, message string) *Migration {
return &Migration{
- Version: fmt.Sprintf("%03d", version),
+ Version: fmt.Sprintf("%04d", version),
Message: message,
Applied: false,
}
diff --git a/internal/models/migration_test.go b/internal/models/migration_test.go
index 87b98e4..91aed2e 100644
--- a/internal/models/migration_test.go
+++ b/internal/models/migration_test.go
@@ -10,13 +10,13 @@ import (
func TestNewMigration(t *testing.T) {
m := models.NewMigration(1, "test message")
- check.Equal(t, m.Version, "001")
+ check.Equal(t, m.Version, "0001")
check.Equal(t, m.Message, "test message")
check.Equal(t, m.Applied, false)
m = models.NewMigration(100, "test message")
- check.Equal(t, m.Version, "100")
+ check.Equal(t, m.Version, "0100")
check.Equal(t, m.Message, "test message")
check.Equal(t, m.Applied, false)
}
@@ -31,12 +31,12 @@ func TestName(t *testing.T) {
// Underscores are used to separate version and message.
{
migration: models.NewMigration(1, "test_message"),
- expectedName: "001_test_message",
+ expectedName: "0001_test_message",
},
// Leading/Trailing spaces trimmed, lowercased, and spaces converted to underscores.
{
migration: models.NewMigration(1, " teST mesSAGE "),
- expectedName: "001_test_message",
+ expectedName: "0001_test_message",
},
}
diff --git a/internal/repositories/migration_fs_repo_test.go b/internal/repositories/migration_fs_repo_test.go
index c3c71c4..4e0936d 100644
--- a/internal/repositories/migration_fs_repo_test.go
+++ b/internal/repositories/migration_fs_repo_test.go
@@ -221,6 +221,6 @@ func TestList_DuplicateMigrationVersion(t *testing.T) {
assert.ErrorContains(
t,
err,
- "001_migration_1 and 001_migration_2 both have version 001; renumber one of them",
+ "0001_migration_1 and 0001_migration_2 both have version 0001; renumber one of them",
)
}
diff --git a/internal/services/migration_test.go b/internal/services/migration_test.go
index 0496299..4b5bdf0 100644
--- a/internal/services/migration_test.go
+++ b/internal/services/migration_test.go
@@ -31,26 +31,26 @@ func TestListMigrations(t *testing.T) {
// Ensure one local fs migration shows up as expected.
{
localFilesystemMigrations: []*models.Migration{
- {Version: "001", Applied: false},
+ {Version: "0001", Applied: false},
},
remoteAppliedMigrations: []*models.Migration{},
sortOrder: SortOrderAsc,
expectedMigrations: []*models.Migration{
- {Version: "001", Applied: false},
+ {Version: "0001", Applied: false},
},
},
// Ensure that one local fs migration and one remote applied migration
// for the same version returns one applied migration.
{
localFilesystemMigrations: []*models.Migration{
- {Version: "001", Applied: false},
+ {Version: "0001", Applied: false},
},
remoteAppliedMigrations: []*models.Migration{
- {Version: "001", Applied: true},
+ {Version: "0001", Applied: true},
},
sortOrder: SortOrderAsc,
expectedMigrations: []*models.Migration{
- {Version: "001", Applied: true},
+ {Version: "0001", Applied: true},
},
},
// Ensure that any applied migrations that don't exist locally
@@ -58,7 +58,7 @@ func TestListMigrations(t *testing.T) {
{
localFilesystemMigrations: []*models.Migration{},
remoteAppliedMigrations: []*models.Migration{
- {Version: "001", Applied: true},
+ {Version: "0001", Applied: true},
},
sortOrder: SortOrderAsc,
expectedMigrations: []*models.Migration{},
@@ -72,12 +72,12 @@ func TestListMigrations(t *testing.T) {
{Version: "1009"},
{Version: "190"},
{Version: "110"},
- {Version: "001"},
+ {Version: "0001"},
},
remoteAppliedMigrations: []*models.Migration{},
sortOrder: SortOrderAsc,
expectedMigrations: []*models.Migration{
- {Version: "001"},
+ {Version: "0001"},
{Version: "110"},
{Version: "190"},
{Version: "1009"},
@@ -89,7 +89,7 @@ func TestListMigrations(t *testing.T) {
// Ensure that migrations are sorted in desc order for sequential migrations
{
localFilesystemMigrations: []*models.Migration{
- {Version: "001"},
+ {Version: "0001"},
{Version: "110"},
{Version: "190"},
{Version: "1009"},
@@ -106,7 +106,7 @@ func TestListMigrations(t *testing.T) {
{Version: "1009"},
{Version: "190"},
{Version: "110"},
- {Version: "001"},
+ {Version: "0001"},
},
},
}
@@ -263,7 +263,7 @@ func TestCreateMigration(t *testing.T) {
migration, err := svc.CreateMigration("new migration")
assert.Nil(t, err)
- check.Equal(t, migration.Version, "001")
+ check.Equal(t, migration.Version, "0001")
check.Equal(t, migration.Message, "new migration")
check.Equal(t, migration.Applied, false)
}
@@ -283,7 +283,7 @@ func TestCreateMigration_NilDbRepo(t *testing.T) {
migration, err := svc.CreateMigration("new migration")
assert.Nil(t, err)
- check.Equal(t, migration.Version, "001")
+ check.Equal(t, migration.Version, "0001")
check.Equal(t, migration.Message, "new migration")
check.Equal(t, migration.Applied, false)
}
@@ -332,7 +332,7 @@ func TestCreateMigration_VersionIncrements(t *testing.T) {
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
Migrations: map[string]*models.Migration{
- "001": {Version: "001"},
+ "0001": {Version: "0001"},
},
Err: nil,
},
@@ -350,16 +350,16 @@ func TestCreateMigration_VersionIncrements(t *testing.T) {
migration, err := svc.CreateMigration("new migration")
assert.Nil(t, err)
- assert.Equal(t, migration.Version, "002")
+ assert.Equal(t, migration.Version, "0002")
}
func TestCreateMigration_VersionIncrementsLatestVersion(t *testing.T) {
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
Migrations: map[string]*models.Migration{
- "001": {Version: "001"},
- "002": {Version: "002"},
- "003": {Version: "003"},
+ "0001": {Version: "0001"},
+ "0002": {Version: "0002"},
+ "0003": {Version: "0003"},
},
Err: nil,
},
@@ -377,7 +377,7 @@ func TestCreateMigration_VersionIncrementsLatestVersion(t *testing.T) {
migration, err := svc.CreateMigration("new migration")
assert.Nil(t, err)
- assert.Equal(t, migration.Version, "004")
+ assert.Equal(t, migration.Version, "0004")
}
func TestCreateMigration_VersionIncrementsParsingErr(t *testing.T) {
@@ -557,8 +557,8 @@ func TestApplyAllMigrations_ListMigrationsErr(t *testing.T) {
func TestApplyAllMigrations_AppliesNothingIfAllApplied(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
- "002": {Version: "002", Applied: true},
+ "0001": {Version: "0001", Applied: true},
+ "0002": {Version: "0002", Applied: true},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -582,7 +582,7 @@ func TestApplyAllMigrations_AppliesNothingIfAllApplied(t *testing.T) {
func TestApplyAllMigrations_ApplyMigrationErr(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
+ "0001": {Version: "0001", Applied: false},
}
expectedErr := errors.New("error!")
migrationFsRepo := &bolttest.MockMigrationFsRepo{
@@ -622,14 +622,14 @@ func TestApplyUpToVersion_ListMigrationsErr(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.ApplyUpToVersion("001")
+ err := svc.ApplyUpToVersion("0001")
assert.ErrorIs(t, err, expectedErr)
}
func TestApplyUpToVersion_TargetMigrationNotFound(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
+ "0001": {Version: "0001", Applied: false},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -643,14 +643,14 @@ func TestApplyUpToVersion_TargetMigrationNotFound(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.ApplyUpToVersion("002")
+ err := svc.ApplyUpToVersion("0002")
- assert.ErrorContains(t, err, "migration with version 002 does not exist")
+ assert.ErrorContains(t, err, "migration with version 0002 does not exist")
}
func TestApplyUpToVersion_TargetMigrationAlreadyApplied(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
+ "0001": {Version: "0001", Applied: true},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -664,14 +664,14 @@ func TestApplyUpToVersion_TargetMigrationAlreadyApplied(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.ApplyUpToVersion("001")
+ err := svc.ApplyUpToVersion("0001")
- assert.ErrorContains(t, err, "migration with version 001 is already applied")
+ assert.ErrorContains(t, err, "migration with version 0001 is already applied")
}
func TestApplyUpToVersion_ApplyMigrationErr(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
+ "0001": {Version: "0001", Applied: false},
}
expectedErr := errors.New("error!")
migrationFsRepo := &bolttest.MockMigrationFsRepo{
@@ -689,16 +689,16 @@ func TestApplyUpToVersion_ApplyMigrationErr(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.ApplyUpToVersion("001")
+ err := svc.ApplyUpToVersion("0001")
assert.ErrorIs(t, err, expectedErr)
}
func TestApplyUpToVersion_AppliesMigrations(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
- "002": {Version: "002", Applied: false},
- "003": {Version: "003", Applied: false},
+ "0001": {Version: "0001", Applied: false},
+ "0002": {Version: "0002", Applied: false},
+ "0003": {Version: "0003", Applied: false},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -712,7 +712,7 @@ func TestApplyUpToVersion_AppliesMigrations(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.ApplyUpToVersion("002")
+ err := svc.ApplyUpToVersion("0002")
assert.Nil(t, err)
assert.Equal(t, migrationFsRepo.ReadUpgradeScriptCallCount, 2)
@@ -861,14 +861,14 @@ func TestRevertDownToVersion_ListMigrationsErr(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.RevertDownToVersion("001")
+ err := svc.RevertDownToVersion("0001")
assert.ErrorIs(t, err, expectedErr)
}
func TestRevertDownToVersion_TargetMigrationNotFound(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
+ "0001": {Version: "0001", Applied: true},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -882,14 +882,14 @@ func TestRevertDownToVersion_TargetMigrationNotFound(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.RevertDownToVersion("002")
+ err := svc.RevertDownToVersion("0002")
- assert.ErrorContains(t, err, "migration with version 002 does not exist")
+ assert.ErrorContains(t, err, "migration with version 0002 does not exist")
}
func TestRevertDownToVersion_TargetMigrationNotApplied(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
+ "0001": {Version: "0001", Applied: false},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -903,14 +903,14 @@ func TestRevertDownToVersion_TargetMigrationNotApplied(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.RevertDownToVersion("001")
+ err := svc.RevertDownToVersion("0001")
- assert.ErrorContains(t, err, "migration with version 001 isn't applied")
+ assert.ErrorContains(t, err, "migration with version 0001 isn't applied")
}
func TestRevertDownToVersion_RevertMigrationErr(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
+ "0001": {Version: "0001", Applied: true},
}
expectedErr := errors.New("error!")
migrationFsRepo := &bolttest.MockMigrationFsRepo{
@@ -928,16 +928,16 @@ func TestRevertDownToVersion_RevertMigrationErr(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.RevertDownToVersion("001")
+ err := svc.RevertDownToVersion("0001")
assert.ErrorIs(t, err, expectedErr)
}
func TestRevertDownToVersion_RevertsMigrations(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
- "002": {Version: "002", Applied: true},
- "003": {Version: "003", Applied: false},
+ "0001": {Version: "0001", Applied: true},
+ "0002": {Version: "0002", Applied: true},
+ "0003": {Version: "0003", Applied: false},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -951,7 +951,7 @@ func TestRevertDownToVersion_RevertsMigrations(t *testing.T) {
bolttest.NullOutputter{},
)
- err := svc.RevertDownToVersion("001")
+ err := svc.RevertDownToVersion("0001")
assert.Nil(t, err)
assert.Equal(t, migrationFsRepo.ReadDowngradeScriptCallCount, 2)
@@ -978,8 +978,8 @@ func TestRevertAllMigrations_ListMigrationsErr(t *testing.T) {
func TestRevertAllMigrations_RevertsNothingIfNoneApplied(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: false},
- "002": {Version: "002", Applied: false},
+ "0001": {Version: "0001", Applied: false},
+ "0002": {Version: "0002", Applied: false},
}
migrationFsRepo := &bolttest.MockMigrationFsRepo{
ListReturnValue: bolttest.ListReturnValue{
@@ -1003,7 +1003,7 @@ func TestRevertAllMigrations_RevertsNothingIfNoneApplied(t *testing.T) {
func TestRevertAllMigrations_RevertMigrationErr(t *testing.T) {
migrations := map[string]*models.Migration{
- "001": {Version: "001", Applied: true},
+ "0001": {Version: "0001", Applied: true},
}
expectedErr := errors.New("error!")
migrationFsRepo := &bolttest.MockMigrationFsRepo{