Skip to content

Commit 49bf500

Browse files
Add an extra test case for missing local migrations (#818)
Ensure that when no migrations have been applied to the target database, the `MissingMigrations` function returns an empty slice. Also, update an error message in the pull command to be more accurate. This should have been part of #811
1 parent 445696d commit 49bf500

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cmd/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func pullCmd() *cobra.Command {
6060
// the target database but are missing in the local directory).
6161
migs, err := m.MissingMigrations(ctx, os.DirFS(targetDir))
6262
if err != nil {
63-
return fmt.Errorf("failed to read migrations from target directory: %w", err)
63+
return fmt.Errorf("failed to get missing migrations: %w", err)
6464
}
6565

6666
// Write the missing migrations to the target directory

pkg/roll/missing_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,24 @@ func TestMissingMigrations(t *testing.T) {
166166
})
167167
})
168168

169+
t.Run("no migrations have been applied to the target database", func(t *testing.T) {
170+
fs := fstest.MapFS{
171+
"01_migration_1.json": &fstest.MapFile{Data: exampleMigJSON(t, "01_migration_1")},
172+
"02_migration_2.json": &fstest.MapFile{Data: exampleMigJSON(t, "02_migration_2")},
173+
}
174+
175+
testutils.WithMigratorAndConnectionToContainer(t, func(m *roll.Roll, _ *sql.DB) {
176+
ctx := context.Background()
177+
178+
// Get missing migrations
179+
migs, err := m.MissingMigrations(ctx, fs)
180+
require.NoError(t, err)
181+
182+
// Assert that no migrations are missing from the local directory
183+
require.Len(t, migs, 0)
184+
})
185+
})
186+
169187
t.Run("migrations with no name use filename as migration name", func(t *testing.T) {
170188
fs := fstest.MapFS{
171189
"01_migration_1.json": &fstest.MapFile{Data: exampleMigJSON(t, "")},

0 commit comments

Comments
 (0)