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 b5d5e53
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions tests/migration_dependency_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package tests

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

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

var _ = Describe("migration dependency", Ordered, func() {
Expand All @@ -18,34 +21,34 @@ var _ = Describe("migration dependency", Ordered, func() {
})

// 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())

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())
}
})
})

0 comments on commit b5d5e53

Please sign in to comment.