"log" "time" ) var TaskOne = gofer.Register(gofer.Task{ Namespace: "accounts", Label: "create", Description: "Create Nico's account", Action: func(arguments ...string) (err error) { log.Println("accounts:create") dbSession, err := api.StartDb("./") if err != nil { log.Fatal(err) } account := &models.Account{ Name: "Test", LastInterestPaid: time.Now(), } serv := &accounts.CreateServ{} _, err = serv.Run(dbSession, *account) if err != nil { log.Fatal(err) } return }, })
"github.com/jinzhu/gorm" _ "github.com/lib/pq" ) var Migrate = gofer.Register(gofer.Task{ Label: "migrate", Description: "Migrate the database because", Action: func() { db, err := gorm.Open("postgres", "dbname=inventory sslmode=disable") if err != nil { fmt.Println(err) } //Get database connection handle [*sql.DB](http://golang.org/pkg/database/sql/#DB) db.DB() // Then you could invoke `*sql.DB`'s functions with it db.DB().Ping() db.DB().SetMaxIdleConns(10) db.DB().SetMaxOpenConns(100) // Disable table name's pluralization db.SingularTable(true) db.CreateTable(&Thing{}) db.CreateTable(&Author{}) db.CreateTable(&Publisher{}) }, })
migrator, migError := gomigrate.NewMigrator(db, gomigrate.Postgres{}, "./migrations") return migrator, migError } var DBMigrate = gofer.Register(gofer.Task{ Namespace: "db", Label: "migrate", Description: "Migrates a database", Action: func(arguments ...string) error { loadError := SetupEnv(arguments) if loadError != nil { return errors.New("env file does not exist") } migrator, migError := SetupMigrator() if migError != nil { return migError } migrateError := migrator.Migrate() if migrateError != nil { return errors.New("Migration failed") } return nil }, }) var DBRollback = gofer.Register(gofer.Task{ Namespace: "db", Label: "rollback",