Skip to content

Commit 73ebe57

Browse files
DavudSafarliory-bot
authored andcommitted
chore: simplify migrationbox internals for testdata
GitOrigin-RevId: f2f288814ebcdb9f01ab53f5530af2c162ac8b27
1 parent ac241fc commit 73ebe57

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

oryx/popx/migration_box.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626
type (
2727
// MigrationBox is a embed migration box.
2828
MigrationBox struct {
29-
c *pop.Connection
30-
migrationsUp Migrations
31-
migrationsDown Migrations
32-
perMigrationTimeout time.Duration
33-
l *logrusx.Logger
34-
migrationContent MigrationContent
35-
disableGoldenDatabase, hasTestData bool
29+
c *pop.Connection
30+
migrationsUp Migrations
31+
migrationsDown Migrations
32+
perMigrationTimeout time.Duration
33+
l *logrusx.Logger
34+
migrationContent MigrationContent
35+
disableGoldenDatabase bool
3636
}
3737
MigrationContent func(mf Migration, c *pop.Connection, r []byte, usingTemplate bool) (string, error)
3838
MigrationBoxOption func(*MigrationBox)
@@ -91,7 +91,9 @@ var testdataPattern = regexp.MustCompile(`^(\d+)_testdata(|\.[a-zA-Z0-9]+).sql$`
9191
// WithTestdata adds testdata to the migration box.
9292
func WithTestdata(t *testing.T, testdata fs.FS) MigrationBoxOption {
9393
return func(m *MigrationBox) {
94-
m.hasTestData = true
94+
// Testdata may not change the golden-database hash,
95+
// so it should not share or create a golden database.
96+
m.disableGoldenDatabase = true
9597
require.NoError(t, fs.WalkDir(testdata, ".", func(path string, info fs.DirEntry, err error) error {
9698
if err != nil {
9799
return errors.WithStack(err)

oryx/popx/migrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (mb *MigrationBox) UpTo(ctx context.Context, step int) (applied int, err er
130130
// using SQLite's online backup API. The restore streams pages directly into
131131
// the open connection, so mb.c stays valid throughout and any holders of
132132
// it (including WithContext copies) keep working.
133-
if testing.Testing() && isOnDiskSQLite && step <= 0 && !mb.disableGoldenDatabase && !mb.hasTestData {
133+
if testing.Testing() && isOnDiskSQLite && step <= 0 && !mb.disableGoldenDatabase {
134134
goldenDbPath := mb.goldenDatabasePath()
135135
if _, statErr := os.Stat(goldenDbPath); statErr == nil {
136136
// Only restore onto a fresh (uninitialized) database. If the

0 commit comments

Comments
 (0)