upgraded migrations and context usage

This commit is contained in:
Fran Jurmanović
2021-07-03 00:01:25 +02:00
parent 4189a0d333
commit 788ff3a146
33 changed files with 321 additions and 251 deletions

View File

@@ -0,0 +1,30 @@
package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10/orm"
)
func CreateTableUsers(db pg.DB) error {
models := []interface{}{
(*models.User)(nil),
}
for _, model := range models {
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
return err
} else {
fmt.Println("Table created successfully")
}
}
return nil
}