This commit is contained in:
Fran Jurmanović
2021-05-06 20:09:29 +02:00
parent 3a5138eb83
commit 20894ee42e
18 changed files with 197 additions and 28 deletions

13
pkg/migrate/migrate.go Normal file
View File

@@ -0,0 +1,13 @@
package migrate
import (
"wallet-api/pkg/migrate/migrations"
"github.com/go-pg/pg/v10"
)
func Start(conn *pg.DB) {
apiMigration := migrations.ApiMigration{Db: conn}
apiMigration.Create()
}

View File

@@ -0,0 +1,31 @@
package migrations
import (
"fmt"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
type ApiMigration struct {
Db *pg.DB
}
func (am *ApiMigration) Create() {
models := []interface{}{
(*models.ApiModel)(nil),
}
for _, model := range models {
err := am.Db.Model(model).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
} else {
fmt.Println("Table created successfully")
}
}
}