]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - db/db.go
Fix migrations.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / db / db.go
index 2596dcb25c24c1daa428f4c526224919c16a1433..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
@@ -55,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
@@ -82,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
@@ -109,6 +101,7 @@ func connect(config DBConfig) *pg.DB {
                User:     config.User,
                Password: config.Password,
                Database: config.Database,
+               Network:  config.Type,
                Addr:     config.Address,
        })
 }