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(migration): add last_heartbet and ready as column of server_instances tables in a separate migration #233

Merged
merged 1 commit into from
Dec 17, 2024
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
4 changes: 0 additions & 4 deletions pkg/db/migrations/202401151014_add_server_instances.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package migrations

import (
"time"

"gorm.io/gorm"

"github.com/go-gormigrate/gormigrate/v2"
Expand All @@ -11,8 +9,6 @@ import (
func addServerInstances() *gormigrate.Migration {
type ServerInstance struct {
Model
LastHeartbeat time.Time
Ready bool `gorm:"default:false"`
}

return &gormigrate.Migration{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package migrations

import (
"time"

"gorm.io/gorm"

"github.com/go-gormigrate/gormigrate/v2"
)

func addLastHeartBeatAndReadyColumnInServerInstancesTable() *gormigrate.Migration {
type ServerInstance struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need Model here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't need the Model.

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")
},
}
}
1 change: 1 addition & 0 deletions pkg/db/migrations/migration_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down