Skip to content

Commit

Permalink
fix id bigint conversation for not created table (#5157)
Browse files Browse the repository at this point in the history
Signed-off-by: YiShengOng <yshengong@gmail.com>
  • Loading branch information
ongkong committed Apr 4, 2024
1 parent 37255a1 commit bcdbf5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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 @@ import (

// 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 @@ var LegacyMigrations = []*gormigrate.Migration{

// 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])
},
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])
},
},

Expand Down Expand Up @@ -1225,7 +1227,7 @@ var ContinuedMigrations = []*gormigrate.Migration{
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

0 comments on commit bcdbf5f

Please sign in to comment.