mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
42 lines
773 B
Go
42 lines
773 B
Go
package migrate
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"wallet-api/pkg/model"
|
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
|
"github.com/go-pg/pg/v10/orm"
|
|
)
|
|
|
|
/*
|
|
CreateTableTransactions
|
|
|
|
Creates transactions table if it does not exist.
|
|
|
|
Args:
|
|
*pg.DB: Postgres database client
|
|
Returns:
|
|
error: Returns if there is an error with table creation
|
|
*/
|
|
func CreateTableTransactions(db *pg.Tx) error {
|
|
models := []interface{}{
|
|
(*model.Transaction)(nil),
|
|
}
|
|
|
|
for _, model := range models {
|
|
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
|
IfNotExists: false,
|
|
FKConstraints: true,
|
|
})
|
|
if err != nil {
|
|
log.Printf("Error creating table \"transactions\": %s", err)
|
|
return err
|
|
} else {
|
|
fmt.Println("Table \"transactions\" created successfully")
|
|
}
|
|
}
|
|
return nil
|
|
}
|