From eddc46d1f49ccc2d3298fed0d4b8ab25c159e357 Mon Sep 17 00:00:00 2001 From: Manyanda Chitimbo Date: Tue, 17 Dec 2024 16:09:24 +0100 Subject: [PATCH] fix(migration): add last_heartbet and ready as column of server_instances tables in a separate migration (#233) Addresses https://github.com/openshift-online/maestro/pull/229/files#r1888513628 as the issue is causing existing deployment to fail with errors like ``` 2024-12-17T13:19:34.107Z ERROR server/healthcheck_server.go:115 Unable to create maestro instance: ERROR: column "last_heartbeat" of relation "server_instances" does not exist (SQLSTATE 42703) github.com/openshift-online/maestro/cmd/maestro/server.(*HealthCheckServer).pulse ``` or ``` 2024-12-17T13:19:54.339Z ERROR server/healthcheck_server.go:184 Unable to mark inactive maestro instances ([maestro-maestro-689869f6dd-5jsbs maestro-maestro-689869f6dd-6tgxq]): ERROR: column "ready" of relation "server_instances" does not exist (SQLSTATE 42703) github.com/openshift-online/maestro/cmd/maestro/server.(*HealthCheckServer).checkInstances ``` --- .../202401151014_add_server_instances.go | 4 --- ...ready_column_in_server_instances_tables.go | 30 +++++++++++++++++++ pkg/db/migrations/migration_structs.go | 1 + 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 pkg/db/migrations/202412171429_add_last_heartbeat_and_ready_column_in_server_instances_tables.go diff --git a/pkg/db/migrations/202401151014_add_server_instances.go b/pkg/db/migrations/202401151014_add_server_instances.go index 2a733721..281481a4 100644 --- a/pkg/db/migrations/202401151014_add_server_instances.go +++ b/pkg/db/migrations/202401151014_add_server_instances.go @@ -1,8 +1,6 @@ package migrations import ( - "time" - "gorm.io/gorm" "github.com/go-gormigrate/gormigrate/v2" @@ -11,8 +9,6 @@ import ( func addServerInstances() *gormigrate.Migration { type ServerInstance struct { Model - LastHeartbeat time.Time - Ready bool `gorm:"default:false"` } return &gormigrate.Migration{ diff --git a/pkg/db/migrations/202412171429_add_last_heartbeat_and_ready_column_in_server_instances_tables.go b/pkg/db/migrations/202412171429_add_last_heartbeat_and_ready_column_in_server_instances_tables.go new file mode 100644 index 00000000..6565e5a0 --- /dev/null +++ b/pkg/db/migrations/202412171429_add_last_heartbeat_and_ready_column_in_server_instances_tables.go @@ -0,0 +1,30 @@ +package migrations + +import ( + "time" + + "gorm.io/gorm" + + "github.com/go-gormigrate/gormigrate/v2" +) + +func addLastHeartBeatAndReadyColumnInServerInstancesTable() *gormigrate.Migration { + type ServerInstance struct { + LastHeartbeat time.Time + Ready bool `gorm:"default:false"` + } + + return &gormigrate.Migration{ + ID: "202412171429", + Migrate: func(tx *gorm.DB) error { + return tx.AutoMigrate(&ServerInstance{}) + }, + Rollback: func(tx *gorm.DB) error { + err := tx.Migrator().DropColumn(&ServerInstance{}, "ready") + if err != nil { + return err + } + return tx.Migrator().DropColumn(&ServerInstance{}, "last_heartbeat") + }, + } +} diff --git a/pkg/db/migrations/migration_structs.go b/pkg/db/migrations/migration_structs.go index 2a5e652b..2707961e 100755 --- a/pkg/db/migrations/migration_structs.go +++ b/pkg/db/migrations/migration_structs.go @@ -34,6 +34,7 @@ var MigrationList = []*gormigrate.Migration{ addServerInstances(), addStatusEvents(), addEventInstances(), + addLastHeartBeatAndReadyColumnInServerInstancesTable(), } // Model represents the base model struct. All entities will have this struct embedded.