Files
wallet-go-api/pkg/migrate/10_create_table_transaction_status.go
2021-09-05 11:40:21 +02:00

41 lines
803 B
Go

package migrate
import (
"fmt"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
/*
CreateTableTransactionStatus
Creates transaction_status table if it does not exist.
Args:
*pg.DB: Postgres database client
Returns:
error: Returns if there is an error with table creation
*/
func CreateTableTransactionStatus(db pg.DB) error {
models := []interface{}{
(*models.TransactionStatus)(nil),
}
for _, model := range models {
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
IfNotExists: false,
FKConstraints: true,
})
if err != nil {
log.Printf("Error creating table \"transaction_status\": %s", err)
return err
} else {
fmt.Println("Table \"transaction_status\" created successfully")
}
}
return nil
}