add cron job to sync currencies once in 24 hours

This commit is contained in:
Fran Jurmanović
2023-04-13 18:10:21 +02:00
parent cf1d4f8b1a
commit 84b00a9ddf
22 changed files with 407 additions and 25 deletions

View 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
}