Пример #1
0
func (s *DriverTestSuite) TestUpAsyncDownAsync() {
	tractor := &tractor.SqlTractor{
		Driver: s.Driver,
		Reader: s.Reader,
	}

	version, _ := tractor.Version()
	s.Equal(uint64(0), version)

	for r := range tractor.UpAsync() {
		s.Nil(r.Error)
	}

	version, _ = tractor.Version()
	s.Equal(uint64(3), version)

	for r := range tractor.DownAsync() {
		s.Nil(r.Error)
	}

	version, _ = tractor.Version()
	s.Equal(uint64(0), version)
}
Пример #2
0
func (s *DriverTestSuite) TestMigrateAsyncUpDown() {
	tractor := &tractor.SqlTractor{
		Driver: s.Driver,
		Reader: s.Reader,
	}

	version, _ := tractor.Version()
	s.Equal(uint64(0), version)

	for r := range tractor.MigrateAsync(+1) {
		s.Nil(r.Error)
	}

	version, _ = tractor.Version()
	s.Equal(uint64(1), version)

	for r := range tractor.MigrateAsync(-1) {
		s.Nil(r.Error)
	}

	version, _ = tractor.Version()
	s.Equal(uint64(0), version)
}
Пример #3
0
func main() {
	flag.Parse()
	command := flag.Arg(0)
	if command == "" || command == "help" {
		printHelpCmd()
		os.Exit(0)
	}

	if *path == "" {
		var err error
		if *path, err = os.Getwd(); err != nil {
			fmt.Println("Please specify path")
			os.Exit(1)
		}
	}

	driver, err := getDriver(*connectionUrl)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	tractor := &tractor.SqlTractor{
		Driver: driver,
		Reader: reader.NewFileReader(*path),
	}

	switch command {
	case "migrate":
		relativeN, err := strconv.Atoi(flag.Arg(1))
		if err != nil {
			fmt.Println("Unable to parse param <n>.")
			os.Exit(1)
		}

		timerStart := time.Now()
		for r := range tractor.MigrateAsync(relativeN) {
			if r.Error != nil {
				printFile(r.File, err)
				os.Exit(1)
			}
			printFile(r.File, nil)
		}
		printTimer(timerStart)

	case "goto":
		toVersion, err := strconv.Atoi(flag.Arg(1))
		if err != nil || toVersion < 0 {
			fmt.Println("Unable to parse param <v>.")
			os.Exit(1)
		}

		currentVersion, err := tractor.Version()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		relativeN := toVersion - int(currentVersion)

		timerStart := time.Now()
		for r := range tractor.MigrateAsync(relativeN) {
			if r.Error != nil {
				printFile(r.File, err)
				os.Exit(1)
			}
			printFile(r.File, nil)
		}
		printTimer(timerStart)

	case "up":
		timerStart := time.Now()
		for r := range tractor.UpAsync() {
			if r.Error != nil {
				printFile(r.File, err)
				os.Exit(1)
			}
			printFile(r.File, nil)
		}
		printTimer(timerStart)

	case "down":
		timerStart := time.Now()
		for r := range tractor.DownAsync() {
			if r.Error != nil {
				printFile(r.File, err)
				os.Exit(1)
			}
			printFile(r.File, nil)
		}
		printTimer(timerStart)

	case "version":
		version, err := tractor.Version()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println(version)
	}
}