Skip to content

Commit

Permalink
Enable database import of apps and dashboards (G-Research#542)
Browse files Browse the repository at this point in the history
* Enabled import of apps and dashboards for migrating to new db, with integration test verification
  • Loading branch information
suprjinx authored Nov 2, 2023
1 parent 691481c commit 322a96c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/database/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewImporter(input, output *gorm.DB) *Importer {
func (s *Importer) Import() error {
tables := []string{
"namespaces",
// "apps",
// "dashboards",
"apps",
"dashboards",
"experiments",
"experiment_tags",
"runs",
Expand Down
46 changes: 29 additions & 17 deletions tests/integration/golang/database/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (s *ImportTestSuite) SetupTest() {

dashboardFixtures, err := fixtures.NewDashboardFixtures(db.GormDB())
assert.Nil(s.T(), err)

// dashboard 1
_, err = dashboardFixtures.CreateDashboard(context.Background(), &database.Dashboard{
Base: database.Base{
ID: uuid.New(),
Expand All @@ -113,6 +115,16 @@ func (s *ImportTestSuite) SetupTest() {
})
assert.Nil(s.T(), err)

// dashboard 2
_, err = dashboardFixtures.CreateDashboard(context.Background(), &database.Dashboard{
Base: database.Base{
ID: uuid.New(),
CreatedAt: time.Now(),
},
AppID: &app.ID,
Name: uuid.NewString(),
})
assert.Nil(s.T(), err)
// prepare output database.
db, err = database.NewDBProvider(
helpers.GetOutputDatabaseUri(),
Expand All @@ -138,7 +150,7 @@ func (s *ImportTestSuite) SetupTest() {
latestMetrics: 20,
tags: 10,
params: 20,
dashboards: 1,
dashboards: 2,
apps: 1,
}
}
Expand Down Expand Up @@ -173,8 +185,8 @@ func (s *ImportTestSuite) Test_Ok() {
// confirm row-for-row equality
for _, table := range []string{
"namespaces",
// "apps",
// "dashboards",
"apps",
"dashboards",
"experiment_tags",
"runs",
"tags",
Expand Down Expand Up @@ -223,13 +235,13 @@ func validateRowCounts(t *testing.T, db *gorm.DB, counts rowCounts) {
assert.Nil(t, tx.Error)
assert.Equal(t, counts.distinctRunExperimentIDs, int(countVal), "Runs experiment association incorrect")

// tx = db.DB.Model(&database.App{}).Count(&countVal)
// assert.Nil(t, tx.Error)
// assert.Equal(t, counts.apps, int(countVal), "Apps count incorrect")
tx = db.Model(&database.App{}).Count(&countVal)
assert.Nil(t, tx.Error)
assert.Equal(t, counts.apps, int(countVal), "Apps count incorrect")

// tx = db.DB.Model(&database.Dashboard{}).Count(&countVal)
// assert.Nil(t, tx.Error)
// assert.Equal(t, counts.dashboards, int(countVal), "Dashboard count incorrect")
tx = db.Model(&database.Dashboard{}).Count(&countVal)
assert.Nil(t, tx.Error)
assert.Equal(t, counts.dashboards, int(countVal), "Dashboard count incorrect")
}

// validateTable will scan source and dest table and confirm they are identical
Expand All @@ -246,22 +258,22 @@ func validateTable(t *testing.T, source, dest *gorm.DB, table string) {
defer destRows.Close()

for sourceRows.Next() {
var sourceItem, destItem map[string]any
var sourceRow, destRow map[string]any

err := source.ScanRows(sourceRows, &sourceItem)
err := source.ScanRows(sourceRows, &sourceRow)
assert.Nil(t, err)

destRows.Next()
err = dest.ScanRows(destRows, &destItem)
err = dest.ScanRows(destRows, &destRow)
assert.Nil(t, err)

// TODO:DSuhinin delete this fields right now, because they
// cause comparison error when we compare `namespace` entities. Let's find smarter way to do that.
delete(destItem, "updated_at")
delete(destItem, "created_at")
delete(sourceItem, "updated_at")
delete(sourceItem, "created_at")
delete(destRow, "updated_at")
delete(destRow, "created_at")
delete(sourceRow, "updated_at")
delete(sourceRow, "created_at")

assert.Equal(t, sourceItem, destItem)
assert.Equal(t, sourceRow, destRow)
}
}

0 comments on commit 322a96c

Please sign in to comment.