]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - db/db.go
bot_setting table.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / db / db.go
index 078cd5895885f5308a13729c3acca58ed2544266..2adc8c870caa159b34211401122cd743e536a84e 100644 (file)
--- 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,
        })
 }