X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=db%2Fdb.go;h=2adc8c870caa159b34211401122cd743e536a84e;hb=8d238416001f2352dcbb76ca2c2af5be5992e987;hp=078cd5895885f5308a13729c3acca58ed2544266;hpb=323b7f4032d19c06523f2eaaf1d20d32e1330b54;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/db/db.go b/db/db.go index 078cd58..2adc8c8 100644 --- a/db/db.go +++ b/db/db.go @@ -16,6 +16,7 @@ var ( ) type DBConfig struct { + Type string // tcp or unix Address string Database string User string @@ -26,6 +27,7 @@ type RedisConfig struct { Type string // tcp or unix Address string Password string + Database int } func Init(config DBConfig, redisConfig RedisConfig) { @@ -42,7 +44,7 @@ func Init(config DBConfig, redisConfig RedisConfig) { Network: redisConfig.Type, Addr: redisConfig.Address, Password: redisConfig.Password, - DB: 0, + DB: redisConfig.Database, }) _, err = Redis.Ping().Result() @@ -54,24 +56,15 @@ func Init(config DBConfig, redisConfig RedisConfig) { } 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 @@ -81,7 +74,7 @@ func migratedb() error { 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 @@ -108,6 +101,7 @@ func connect(config DBConfig) *pg.DB { User: config.User, Password: config.Password, Database: config.Database, + Network: config.Type, Addr: config.Address, }) }