)
type DBConfig struct {
+ Type string // tcp or unix
Address string
Database string
User string
Type string // tcp or unix
Address string
Password string
+ Database int
}
func Init(config DBConfig, redisConfig RedisConfig) {
Network: redisConfig.Type,
Addr: redisConfig.Address,
Password: redisConfig.Password,
- DB: 0,
+ DB: redisConfig.Database,
})
_, err = Redis.Ping().Result()
}
func migratedb() error {
- /* Remove after first MEP */
- version, err := migrate.Version(DB)
- if err != nil {
- return err
- }
-
- if version == 0 {
- return migrate.SetVersion(DB, 1)
- }
- /***/
mig := make([]migrate.Migration, 0)
- for _, migration := range migrations {
+ for i := range migrations {
+ index := i
mig = append(mig, migrate.Migration{
- Version: migration.Version,
+ Version: migrations[index].Version,
Up: func(db orm.DB) error {
- for _, query := range migration.Up {
+ for _, query := range migrations[index].Up {
_, err := db.Exec(query)
if err != nil {
return err
return nil
},
Down: func(db orm.DB) error {
- for _, query := range migration.Down {
+ for _, query := range migrations[index].Down {
_, err := db.Exec(query)
if err != nil {
return err
User: config.User,
Password: config.Password,
Database: config.Database,
+ Network: config.Type,
Addr: config.Address,
})
}