mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
WA-10 - Implemented transactions
This commit is contained in:
32
pkg/migrate/migrations/transactionTypes.go
Normal file
32
pkg/migrate/migrations/transactionTypes.go
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
32
pkg/migrate/migrations/transactions.go
Normal file
32
pkg/migrate/migrations/transactions.go
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user