Files
wallet-go-api/pkg/migrate/migrations/users.go
2021-05-25 21:36:41 +02:00

34 lines
549 B
Go

package migrations
import (
"fmt"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
type UsersMigration struct {
Db *pg.DB
}
func (am *UsersMigration) Create() error {
models := []interface{}{
(*models.User)(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)
return err
} else {
fmt.Println("Table created successfully")
}
}
return nil
}