コード例 #1
0
ファイル: accounts.go プロジェクト: sporto/kic
	"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
	},
})
コード例 #2
0
ファイル: db_migration.go プロジェクト: sklise/inventory
	"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{})
	},
})
コード例 #3
0
ファイル: db.go プロジェクト: gshilin/shidur-go
	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",