mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
add cron job to sync currencies once in 24 hours
This commit is contained in:
@@ -27,7 +27,7 @@ func CreateTableTransactionStatus(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
40
pkg/migrate/12_create_table_currencies.go
Normal file
40
pkg/migrate/12_create_table_currencies.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
/*
|
||||
CreateTableCurrencies
|
||||
|
||||
Creates Currencies table if it does not exist.
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableCurrencies(db *pg.Tx) error {
|
||||
models := []interface{}{
|
||||
(*model.Currency)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error creating table \"currencies\": %s", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Table \"currencies\" created successfully")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func CreateTableWallets(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ func CreateTableTransactionTypes(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ func CreateTableTransactions(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ func CreateTableSubscriptionTypes(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -26,7 +26,7 @@ func CreateTableSubscriptions(db *pg.Tx) error {
|
||||
|
||||
for _, model := range models {
|
||||
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
|
||||
IfNotExists: false,
|
||||
IfNotExists: true,
|
||||
FKConstraints: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -48,12 +48,19 @@ func Start(conn *pg.DB, version string) []error {
|
||||
CreateTableTransactions,
|
||||
},
|
||||
}
|
||||
migration005 := Migration{
|
||||
Version: "005",
|
||||
Migrations: []interface{}{
|
||||
CreateTableCurrencies,
|
||||
},
|
||||
}
|
||||
|
||||
migrationsMap := []Migration{
|
||||
migration001,
|
||||
migration002,
|
||||
migration003,
|
||||
migration004,
|
||||
migration005,
|
||||
}
|
||||
|
||||
var errors []error
|
||||
|
||||
Reference in New Issue
Block a user