Skip to content

Commit

Permalink
test: Ensure migration will be executed even with past timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Sep 14, 2024
1 parent 1bd3b80 commit a2e4d9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/pkg/dbx/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ func TestMigrate_Success(t *testing.T) {
trx.MustRollback()
}

func TestMigrate_SuccessWithPastMigration(t *testing.T) {
setupMigrationTest(t)
ctx := context.Background()

err := dbx.Migrate(ctx, "/app/pkg/dbx/testdata/migration_success")
Expect(err).IsNil()

err = dbx.Migrate(ctx, "/app/pkg/dbx/testdata/migration_success_with_new_migrations")
Expect(err).IsNil()

trx, _ := dbx.BeginTx(ctx)
var version string
err = trx.Scalar(&version, "SELECT version FROM migrations_history WHERE version = '209901010000' LIMIT 1")

Check failure on line 54 in app/pkg/dbx/migrate_test.go

View workflow job for this annotation

GitHub Actions / test-server (x86_64)

ineffectual assignment to err (ineffassign)

Check failure on line 54 in app/pkg/dbx/migrate_test.go

View workflow job for this annotation

GitHub Actions / test-server (arm64)

ineffectual assignment to err (ineffassign)
Expect(version).Equals("209901010000")
var count int
err = trx.Scalar(&count, "SELECT COUNT(*) FROM migrations_history where VERSION IN (209901010000,210001010002)")
Expect(err).IsNil()
Expect(count).Equals(2)
trx.MustRollback()
}

func TestMigrate_Failure(t *testing.T) {
setupMigrationTest(t)
ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into dummy (id, description) values (400, 'Description 400A');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM dummy WHERE id = 400;

0 comments on commit a2e4d9a

Please sign in to comment.