Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Id bigint conversation for not yet created table #5157

Merged
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
8 changes: 5 additions & 3 deletions flyteadmin/pkg/repositories/config/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// TODO: add a way to get these list of tables directly from the gorm loaded models
var (
// Tables are ordererd by creation. Migration code relies on this ordering.
tables = []string{"execution_events", "executions", "launch_plans", "named_entity_metadata",
"node_execution_events", "node_executions", "projects", "resources", "schedulable_entities",
"schedule_entities_snapshots", "task_executions", "tasks", "workflows", "description_entities"}
Expand Down Expand Up @@ -347,21 +348,22 @@

// For any new table, Please use the following pattern due to a bug
// in the postgres gorm layer https://github.com/go-gorm/postgres/issues/65
// The 13th table in tables was created before this migration.
{
ID: "2022-01-11-id-to-bigint",
Migrate: func(tx *gorm.DB) error {
db, err := tx.DB()
if err != nil {
return err
}
return alterTableColumnType(db, "id", "bigint")
return alterTableColumnType(db, "id", "bigint", tables[:13])

Check warning on line 359 in flyteadmin/pkg/repositories/config/migrations.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/repositories/config/migrations.go#L359

Added line #L359 was not covered by tests
},
Rollback: func(tx *gorm.DB) error {
db, err := tx.DB()
if err != nil {
return err
}
return alterTableColumnType(db, "id", "int")
return alterTableColumnType(db, "id", "int", tables[:13])

Check warning on line 366 in flyteadmin/pkg/repositories/config/migrations.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/repositories/config/migrations.go#L366

Added line #L366 was not covered by tests
},
},

Expand Down Expand Up @@ -1225,7 +1227,7 @@
var m = append(LegacyMigrations, NoopMigrations...)
var Migrations = append(m, ContinuedMigrations...)

func alterTableColumnType(db *sql.DB, columnName, columnType string) error {
func alterTableColumnType(db *sql.DB, columnName, columnType string, tables []string) error {
var err error
for _, table := range tables {
if _, err = db.Exec(fmt.Sprintf(`ALTER TABLE IF EXISTS %s ALTER COLUMN "%s" TYPE %s`, table, columnName,
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/repositories/config/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAlterTableColumnType(t *testing.T) {
`ALTER TABLE IF EXISTS execution_events ALTER COLUMN "id" TYPE bigint`)
assert.NoError(t, err)
tables = []string{"execution_events"}
_ = alterTableColumnType(db, "id", "bigint")
_ = alterTableColumnType(db, "id", "bigint", tables)
assert.True(t, query.Triggered)
}

Expand Down
Loading