Exemple #1
0
// Down rolls back all migrations.
func Down(pipe chan interface{}, url, migrationsPath string) {
	d, files, versions, err := initDriverAndReadMigrationFilesAndGetVersions(url, migrationsPath)
	defer func() {
		if err != nil {
			pipe <- err

		}
		if d != nil {
			if err = d.Close(); err != nil {
				pipe <- err
			}
		}
		go pipep.Close(pipe, nil)
	}()
	if err != nil {
		return
	}

	applyMigrationFiles, err := files.Applied(versions)
	if err != nil {
		return
	}

	if len(applyMigrationFiles) > 0 {
		for _, f := range applyMigrationFiles {
			pipe1 := pipep.New()
			go d.Migrate(f, pipe1)
			if ok := pipep.WaitAndRedirect(pipe1, pipe, handleInterrupts()); !ok {
				break
			}
		}
	}
}
Exemple #2
0
// Reset runs the down and up migration function.
func Reset(pipe chan interface{}, url, migrationsPath string) {
	pipe1 := pipep.New()
	go Down(pipe1, url, migrationsPath)
	if ok := pipep.WaitAndRedirect(pipe1, pipe, handleInterrupts()); !ok {
		go pipep.Close(pipe, nil)
		return
	}
	go Up(pipe, url, migrationsPath)
}