Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
venkat-iblox committed Oct 9, 2024
1 parent 7c91e46 commit 877fe9b
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN go mod download

COPY . ./

RUN make build-docker
#RUN make build-docker

FROM alpine:latest

Expand Down
Binary file added build/migrate.linux-386
Binary file not shown.
7 changes: 7 additions & 0 deletions builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

make build-docker
make build
docker tag infoblox/migrate:5.0.0-2-g8ab5a72-unsupported-j0 core-harbor-prod.sdp.infoblox.com/infobloxcto-dev/infoblox/migrate:5.0.0-2-g8ab5a72-unsupported-j0
docker push core-harbor-prod.sdp.infoblox.com/infobloxcto-dev/infoblox/migrate:5.0.0-2-g8ab5a72-unsupported-j0
docker run -it -v /Users/vvenkatasubramanian/go/src/github.com/Infoblox-CTO/ddi.keys/db/migrations/:/ns-migrations/ --net host --entrypoint /bin/sh core-harbor-prod.sdp.infoblox.com/infobloxcto-dev/infoblox/migrate:5.0.0-2-g8ab5a72-unsupported-j0
409 changes: 409 additions & 0 deletions coverage/combined.txt

Large diffs are not rendered by default.

Binary file added migrate
Binary file not shown.
12 changes: 5 additions & 7 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Migrate struct {
// but can be set per Migrate instance.
LockTimeout time.Duration

// DirtyStateHandler is used to handle dirty state of the database
// dirtyStateConfig is used to store the configuration required to handle dirty state of the database
dirtyStateConf *dirtyStateConfig
}

Expand Down Expand Up @@ -224,13 +224,11 @@ func (m *Migrate) WithDirtyStateConfig(srcPath, destPath string, isDirty bool) e
if err != nil {
return "", "", err
}
scheme := uri.Scheme
if scheme == "" || scheme == "file" {
scheme = "file://"
} else if scheme != "file" {
scheme := "file"
if uri.Scheme != "file" && uri.Scheme != "" {
return "", "", fmt.Errorf("unsupported scheme: %s", scheme)
}
return scheme, uri.Path, nil
return scheme + "://", uri.Path, nil
}

sScheme, sPath, err := parsePath(srcPath)
Expand Down Expand Up @@ -1091,7 +1089,7 @@ func (m *Migrate) handleDirtyState() error {
3. Set the last successful migration version in the schema_migrations table
4. Delete the last successful migration file
*/
// the source driver should read the migrations from the mounted volume
// the source driver should read the migrations from the destination path
// as the DB is dirty and last applied migrations to the database are not present in the source path
if err := m.updateSourceDrv(m.dirtyStateConf.destScheme + m.dirtyStateConf.destPath); err != nil {
return err
Expand Down
40 changes: 6 additions & 34 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,17 +1418,6 @@ func equalDbSeq(t *testing.T, i int, expected migrationSequence, got *dStub.Stub
}
}

// Setting up temp directory to be used as the volume mount
func setupTempDir(t *testing.T) (string, func()) {
tempDir := t.TempDir()

return tempDir, func() {
if err := os.RemoveAll(tempDir); err != nil {
t.Fatal(err)
}
}
}

func setupMigrateInstance(tempDir string) (*Migrate, *dStub.Stub) {
scheme := "stub://"
m, _ := New(scheme, scheme)
Expand All @@ -1441,8 +1430,7 @@ func setupMigrateInstance(tempDir string) (*Migrate, *dStub.Stub) {
}

func TestHandleDirtyState(t *testing.T) {
tempDir, cleanup := setupTempDir(t)
defer cleanup()
tempDir := t.TempDir()

m, dbDrv := setupMigrateInstance(tempDir)
m.sourceDrv.(*sStub.Stub).Migrations = sourceStubMigrations
Expand Down Expand Up @@ -1519,8 +1507,7 @@ func TestHandleDirtyState(t *testing.T) {
}

func TestHandleMigrationFailure(t *testing.T) {
tempDir, cleanup := setupTempDir(t)
defer cleanup()
tempDir := t.TempDir()

m, _ := setupMigrateInstance(tempDir)

Expand Down Expand Up @@ -1557,8 +1544,7 @@ func TestHandleMigrationFailure(t *testing.T) {
}

func TestCleanupFiles(t *testing.T) {
tempDir, cleanup := setupTempDir(t)
defer cleanup()
tempDir := t.TempDir()

m, _ := setupMigrateInstance(tempDir)
m.sourceDrv.(*sStub.Stub).Migrations = sourceStubMigrations
Expand Down Expand Up @@ -1622,11 +1608,8 @@ func TestCleanupFiles(t *testing.T) {
}

func TestCopyFiles(t *testing.T) {
srcDir, cleanupSrc := setupTempDir(t)
defer cleanupSrc()

destDir, cleanupDest := setupTempDir(t)
defer cleanupDest()
srcDir := t.TempDir()
destDir := t.TempDir()

m, _ := setupMigrateInstance(destDir)
m.dirtyStateConf.srcPath = srcDir
Expand Down Expand Up @@ -1748,24 +1731,13 @@ func TestWithDirtyStateConfig(t *testing.T) {
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !compareDirtyStateConfig(m.dirtyStateConf, tt.wantConf) {
if !tt.wantErr && m.dirtyStateConf == tt.wantConf {
t.Errorf("dirtyStateConf = %v, want %v", m.dirtyStateConf, tt.wantConf)
}
})
}
}

func compareDirtyStateConfig(a, b *dirtyStateConfig) bool {
if a == nil || b == nil {
return a == b
}
return a.srcScheme == b.srcScheme &&
a.srcPath == b.srcPath &&
a.destScheme == b.destScheme &&
a.destPath == b.destPath &&
a.enable == b.enable
}

/*
diff returns an array containing the elements in Array A and not in B
*/
Expand Down

0 comments on commit 877fe9b

Please sign in to comment.