Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package migrations

import (
gormigrate "github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

func dropClusterPlatformIsExternal() *gormigrate.Migration {
migrate := func(tx *gorm.DB) error {
var err error

if err = tx.Exec("ALTER TABLE clusters DROP COLUMN IF EXISTS platform_is_external").Error; err != nil {
return err
}
return nil
}

rollback := func(tx *gorm.DB) error {
// No rollback because automigrate will add the column back for a source version with the column
return nil
}

return &gormigrate.Migration{
ID: "20240918161800",
Migrate: gormigrate.MigrateFunc(migrate),
Rollback: gormigrate.RollbackFunc(rollback),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package migrations

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/assisted-service/internal/common"
"gorm.io/gorm"
)

var _ = Describe("dropClusterPlatformIsExternal", func() {
var (
db *gorm.DB
dbName string
)

BeforeEach(func() {
db, dbName = common.PrepareTestDB()
})

AfterEach(func() {
common.DeleteTestDB(db, dbName)
})

It("succeeds when the platform_is_external column is present", func() {
Expect(migrateToBefore(db, "20240918161800")).To(Succeed())

Expect(db.Exec("ALTER TABLE clusters ADD COLUMN IF NOT EXISTS platform_is_external BOOLEAN").Error).ToNot(HaveOccurred())
Expect(db.Migrator().HasColumn("clusters", "platform_is_external")).To(BeTrue())

Expect(migrateTo(db, "20240918161800")).To(Succeed())
Expect(db.Migrator().HasColumn("clusters", "platform_is_external")).To(BeFalse())
})

It("succeeds when the platform_is_external column is not present", func() {
Expect(migrateToBefore(db, "20240918161800")).To(Succeed())
Expect(db.Migrator().HasColumn("clusters", "platform_is_external")).To(BeFalse())

Expect(migrateTo(db, "20240918161800")).To(Succeed())
Expect(db.Migrator().HasColumn("clusters", "platform_is_external")).To(BeFalse())
})
})
1 change: 1 addition & 0 deletions internal/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func post() []*gormigrate.Migration {
deleteEventsWithUnboundCluster(),
dropClusterApiVipAndIngressVip(),
updateOciToExternalPlatformType(),
dropClusterPlatformIsExternal(),
}

sort.SliceStable(postMigrations, func(i, j int) bool { return postMigrations[i].ID < postMigrations[j].ID })
Expand Down