Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ func (d *DB) UpdateSchema(reportEnd *time.Time) error {
&models.ProwJobRunAnnotation{},
&models.Test{},
&models.Suite{},
&models.ProwJobRunTest{},
&models.ProwJobRunTestOutput{},
&models.APISnapshot{},
&models.Bug{},
&models.ProwPullRequest{},
Expand All @@ -104,13 +102,40 @@ func (d *DB) UpdateSchema(reportEnd *time.Time) error {
}
}

// while we are in the transition phase we have to check to see if the table exists for the models we are migrating
// if not then this is a new db so we should create the old non-partitioned tables
modelsToInitialize := []struct {
model interface{}
tableName string
}{
{
model: &models.ProwJobRunTest{},
tableName: "prow_job_run_tests",
},
{
model: &models.ProwJobRunTestOutput{},
tableName: "prow_job_run_test_outputs",
},
}
for _, model := range modelsToInitialize {
if !d.DB.Migrator().HasTable(model.tableName) {
if err := d.DB.AutoMigrate(model.model); err != nil {
return err
}
}
}

// TODO(sgoeddel): This migration logic can be removed once we have a migration that drops the view column from test_regressions
if d.DB.Migrator().HasColumn(&models.TestRegression{}, "view") {
if err := d.DB.Migrator().DropColumn(&models.TestRegression{}, "view"); err != nil {
return err
}
}

// TODO(fbabcock): Add support for migrating partitioned table
// &models.ProwJobRunTest{},
// &models.ProwJobRunTestOutput{},

if err := createAuditLogIndexes(d.DB); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/db/models/prow.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Test struct {

// ProwJobRunTest defines a join table linking tests to the job runs they execute in, along with the status for
// that execution.
// Do not update until after partitions have been enabled
type ProwJobRunTest struct {
gorm.Model
ProwJobRunID uint `gorm:"index"`
Expand All @@ -102,6 +103,7 @@ type ProwJobRunTest struct {
ProwJobRunTestOutput *ProwJobRunTestOutput `gorm:"constraint:OnDelete:CASCADE;"`
}

// Do not update until after partitions have been enabled
type ProwJobRunTestOutput struct {
gorm.Model
ProwJobRunTestID uint `gorm:"index"`
Expand Down