WA-10 - Implemented transactions

This commit is contained in:
Fran Jurmanović
2021-05-16 17:43:58 +02:00
parent 55010c83d6
commit a99b44194a
8 changed files with 251 additions and 0 deletions

View File

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

View File

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