Esempio n. 1
0
func showVersions(ctx *cli.Context) (bool, error) {
	if len(ctx.Args()) != 0 {
		return true, errorInvalidArgCount(len(ctx.Args()), 0, ctx.Args())
	}

	e := etcd2.New(ctx.GlobalString("prefix"), ctx.GlobalStringSlice("etcd"))

	fmt.Printf("Current local schema version: %d\n", e.CurrentSchemaVersion())
	fmt.Printf("Newest available schema version: %d\n", latestMigrationVersion)

	return false, nil
}
Esempio n. 2
0
func runMigrations(ctx *cli.Context) (bool, error) {
	e := etcd2.New(ctx.GlobalString("prefix"), ctx.GlobalStringSlice("etcd"))

	if len(ctx.Args()) > 0 {
		i, err := strconv.Atoi(ctx.Args()[0])
		if err != nil {
			return true, errored.Errorf("Invalid migration version: %v", ctx.Args()[0])
		}

		targetVersion := int64(i)

		if targetVersion < 1 || targetVersion > latestMigrationVersion {
			return false, errored.Errorf("%d is outside valid migration range - min: 1, max %d", targetVersion, latestMigrationVersion)
		}

		promptBeforeRunning(ctx, fmt.Sprintf("You have requested to run all pending migrations up to and including #%d.", targetVersion))
		return runMigrationsUpTo(e, targetVersion)
	}

	promptBeforeRunning(ctx, "You have requested to run all pending migrations.")
	return runAllMigrations(e)
}