mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
upgraded migrations and context usage
This commit is contained in:
30
pkg/migrate/3_create_table_wallets.go
Normal file
30
pkg/migrate/3_create_table_wallets.go
Normal 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 CreateTableWallets(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.Wallet)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error Creating Table: %s", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Table created successfully")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user