DB Migrations #67
|
@ -21,7 +21,9 @@ import (
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"src.techknowlogick.com/xormigrate"
|
"src.techknowlogick.com/xormigrate"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +65,27 @@ func Migrate(x *xorm.Engine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListMigrations() {
|
func ListMigrations() {
|
||||||
|
x, err := db.CreateDBEngine()
|
||||||
|
if err != nil {
|
||||||
|
log.Log.Fatalf("Could not connect to db: %v", err.Error())
|
||||||
|
}
|
||||||
|
ms := []*xormigrate.Migration{}
|
||||||
|
err = x.Find(&ms)
|
||||||
|
if err != nil {
|
||||||
|
log.Log.Fatalf("Error getting migration table: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
table.SetHeader([]string{"ID", "Description"})
|
||||||
|
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
|
|
||||||
|
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor},
|
||||||
|
tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor})
|
||||||
|
|
||||||
|
for _, m := range ms {
|
||||||
|
table.Append([]string{m.ID, m.Description})
|
||||||
|
}
|
||||||
|
table.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Rollback(until string) {
|
func Rollback(until string) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user