Skip to content

Commit

Permalink
fix: migration dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 23, 2024
1 parent 980dfad commit 92c3ad9
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions tests/migration_dependency_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package tests

import (
"github.com/flanksource/duty/migrate"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/flanksource/commons/collections"
"github.com/flanksource/duty/api"
"github.com/flanksource/duty/migrate"
)

var _ = Describe("migration dependency", Ordered, func() {
var connString string

BeforeAll(func() {
connString = DefaultContext.Value("db_url").(string)
})

It("should have no executable scripts", func() {
db, err := DefaultContext.DB().DB()
Expect(err).To(BeNil())
Expand All @@ -17,35 +26,34 @@ var _ = Describe("migration dependency", Ordered, func() {
Expect(len(views)).To(BeZero())
})

// FIXME: sql driver issue on CI
// It("should get correct executable scripts", func() {
// err := DefaultContext.DB().Exec(`UPDATE migration_logs SET hash = 'dummy' WHERE path = 'drop.sql'`).Error
// Expect(err).To(BeNil())
//
// db, err := DefaultContext.DB().DB()
// Expect(err).To(BeNil())
//
// funcs, views, err := migrate.GetExecutableScripts(db)
// Expect(err).To(BeNil())
// Expect(len(funcs)).To(Equal(1))
// Expect(len(views)).To(Equal(2))
//
// Expect(collections.MapKeys(funcs)).To(Equal([]string{"drop.sql"}))
// Expect(collections.MapKeys(views)).To(ConsistOf([]string{"006_config_views.sql", "021_notification.sql"}))
//
// {
// // run the migrations again to ensure that the hashes are repopulated
// err := migrate.RunMigrations(db, api.DefaultConfig)
// Expect(err).To(BeNil())
//
// // at the end, there should be no scrips to apply
// db, err := DefaultContext.DB().DB()
// Expect(err).To(BeNil())
//
// funcs, views, err := migrate.GetExecutableScripts(db)
// Expect(err).To(BeNil())
// Expect(len(funcs)).To(BeZero())
// Expect(len(views)).To(BeZero())
// }
// })
It("should get correct executable scripts", func() {
err := DefaultContext.DB().Exec(`UPDATE migration_logs SET hash = 'dummy' WHERE path = 'drop.sql'`).Error
Expect(err).To(BeNil())

sqlDB, err := DefaultContext.DB().DB()
Expect(err).To(BeNil())

funcs, views, err := migrate.GetExecutableScripts(sqlDB)
Expect(err).To(BeNil())
Expect(len(funcs)).To(Equal(1))
Expect(len(views)).To(Equal(2))

Expect(collections.MapKeys(funcs)).To(Equal([]string{"drop.sql"}))
Expect(collections.MapKeys(views)).To(ConsistOf([]string{"006_config_views.sql", "021_notification.sql"}))

{
// run the migrations again to ensure that the hashes are repopulated
err := migrate.RunMigrations(sqlDB, api.Config{ConnectionString: connString})
Expect(err).To(BeNil())

// at the end, there should be no scrips to apply
db, err := DefaultContext.DB().DB()
Expect(err).To(BeNil())

funcs, views, err := migrate.GetExecutableScripts(db)
Expect(err).To(BeNil())
Expect(len(funcs)).To(BeZero())
Expect(len(views)).To(BeZero())
}
})
})

0 comments on commit 92c3ad9

Please sign in to comment.