DB Migrations #67

Merged
konrad merged 44 commits from feature/migrations into master 2019-03-29 17:54:36 +00:00
Showing only changes of commit 568ad3774a - Show all commits

View File

@ -62,6 +62,7 @@ func Migrate(x *xorm.Engine) {
if err != nil { if err != nil {
log.Log.Fatalf("Migration failed: %v", err) log.Log.Fatalf("Migration failed: %v", err)
} }
log.Log.Info("Ran all migrations successfully.")
} }
func ListMigrations() { func ListMigrations() {
@ -78,7 +79,6 @@ func ListMigrations() {
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Description"}) table.SetHeader([]string{"ID", "Description"})
table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor}, table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor}) tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor})
@ -88,8 +88,13 @@ func ListMigrations() {
table.Render() table.Render()
} }
func Rollback(until string) { func Rollback(migrationID string) {
m := initMigration(nil)
err := m.RollbackTo(migrationID)
if err != nil {
log.Log.Fatalf("Could not rollback: %v", err)
}
log.Log.Info("Rolled back successfully.")
} }
// Deletes a column from a table. All arguments are strings, to let them be standalone and not depending on any struct. // Deletes a column from a table. All arguments are strings, to let them be standalone and not depending on any struct.