func statusCmd(c *cli.Context) { migrationsPath := c.GlobalString("migrations") targetPath := c.GlobalString("target") migrationsPath, err := migrations.AbsMigrationsPath(migrationsPath) if err != nil { fmt.Printf("Error determining the migrations path: %s\n", err.Error()) os.Exit(1) } list, err := migrations.List(migrationsPath) if err != nil { fmt.Printf("Error listing the available migrations: %s\n", err.Error()) os.Exit(1) } timestamp, err := migrations.CurrentTimestamp(targetPath) if err != nil { fmt.Printf("Error reading the current timestamp: %s\n", err.Error()) os.Exit(1) } if last := migrations.Last(list, timestamp); last != nil { fmt.Printf("Last migration executed: %s\n", last.Name) } else { fmt.Printf("No migration executed yet!\n") } fmt.Printf("Pending migrations: %d\n", len(migrations.Pending(list, timestamp))) }
func runCmd(c *cli.Context) { migrationsPath := c.GlobalString("migrations") targetPath := c.GlobalString("target") migrationsPath, err := migrations.AbsMigrationsPath(migrationsPath) if err != nil { log.Fatal("Error determining the migrations path: " + err.Error()) os.Exit(1) } list, err := migrations.List(migrationsPath) if err != nil { log.Fatal("Error listing the available migrations: " + err.Error()) os.Exit(1) } timestamp, err := migrations.CurrentTimestamp(targetPath) if err != nil { log.Fatal("Error reading the current timestamp: " + err.Error()) os.Exit(1) } pending := migrations.Pending(list, timestamp) migrations.Run(pending, targetPath) }
func listCmd(c *cli.Context) { migrationsPath := c.GlobalString("migrations") targetPath := c.GlobalString("target") migrationsPath, err := migrations.AbsMigrationsPath(migrationsPath) if err != nil { fmt.Printf("Error determining the migrations path: %s\n", err.Error()) os.Exit(1) } list, err := migrations.List(migrationsPath) if err != nil { fmt.Printf("Error listing the available migrations: %s\n", err.Error()) os.Exit(1) } timestamp, err := migrations.CurrentTimestamp(targetPath) if err != nil { fmt.Printf("Error reading the current timestamp: %s\n", err.Error()) os.Exit(1) } if len(list) == 0 { fmt.Println("No migrations found") os.Exit(0) } for _, migration := range list { var symbol string needs := migrations.NeedsToRun(timestamp, migration) if needs { symbol = "✘" } else { symbol = "✔" } fmt.Printf("%s - %s\n", symbol, migration.Name) } }