Esempio n. 1
0
func (s Notifications) MigrateDatabase() {
	env := application.NewEnvironment()
	database, gobbleDB := fetchDatabases()

	migrator := v1models.DatabaseMigrator{}
	migrator.Migrate(database.RawConnection(), env.ModelMigrationsPath)

	gobbleDB.Migrate(env.GobbleMigrationsPath)
}
Esempio n. 2
0
func (s Notifications) ResetDatabase() {
	env := application.NewEnvironment()
	database, gobbleDB := fetchDatabases()

	v1models.Setup(database)
	v2models.Setup(database)
	database.Connection().(*db.Connection).TruncateTables()

	migrator := v1models.DatabaseMigrator{}
	migrator.Seed(database, path.Join(env.RootPath, "templates", "default.json"))

	gobbleDB.Connection.TruncateTables()
}
Esempio n. 3
0
func TruncateTables(database *db.DB) {
	env := application.NewEnvironment()
	dbMigrator := v1models.DatabaseMigrator{}
	dbMigrator.Migrate(database.RawConnection(), env.ModelMigrationsPath)
	v1models.Setup(database)
	v2models.Setup(database)

	connection := database.Connection().(*db.Connection)
	err := connection.TruncateTables()
	if err != nil {
		panic(err)
	}
}
package models_test

import (
	"github.com/cloudfoundry-incubator/notifications/application"
	"github.com/cloudfoundry-incubator/notifications/db"
	"github.com/cloudfoundry-incubator/notifications/testing/helpers"
	"github.com/cloudfoundry-incubator/notifications/v1/models"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("DatabaseMigrator", func() {
	var (
		database            *db.DB
		connection          *db.Connection
		dbMigrator          models.DatabaseMigrator
		defaultTemplatePath string
	)

	BeforeEach(func() {
		env := application.NewEnvironment()
		defaultTemplatePath = env.RootPath + "/templates/default.json"
		database = db.NewDatabase(sqlDB, db.Config{
			DefaultTemplatePath: defaultTemplatePath,
		})
		helpers.TruncateTables(database)
		connection = database.Connection().(*db.Connection)
		dbMigrator = models.DatabaseMigrator{}
	})

	Describe("migrating the database", func() {