Exemplo n.º 1
0
func migrateUp(service versioning.IMaintainVersions,
	migratables []files.MigrationFile) error {
	stack := &Stack{}
	incrementalInterval := time.Duration(int64(0))
	for _, m := range migratables {
		script := Script{Version: m.Version, Stmts: m.Down}
		stack.Push(script)

		fmt.Printf("Upgrading to version: %d \n", m.Version)
		err := service.ApplyChanges(m.Up)
		if err != nil {
			revertUpgrades(stack, service)
			return err
		}
		aon := time.Now().Add(incrementalInterval)
		ad := service.AddVersion(m.Version, m.Description, aon)
		if ad != nil {
			revertUpgrades(stack, service)
			return ad
		}

		incrementalInterval += time.Second //prevents it from having the same time, which throws the cluster sort
	}
	return nil
}
Exemplo n.º 2
0
func migrateDown(n Script, service versioning.IMaintainVersions) error {
	fmt.Printf("Downgrading from version: %d \n", n.Version)
	if err := service.ApplyChanges(n.Stmts); err != nil {
		return err
	}
	if err := service.RemoveVersion(n.Version); err != nil {
		return err
	}
	return nil
}