mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
partial repository layer added
This commit is contained in:
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
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
|
||||
|
||||
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),
|
||||
(*model.TransactionStatus)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
@@ -12,15 +12,16 @@ import (
|
||||
PopulateTransactionStatus
|
||||
|
||||
Populates transaction_status table if it exists.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
*/
|
||||
func PopulateTransactionStatus(db pg.DB) error {
|
||||
completed := new(models.TransactionStatus)
|
||||
pending := new(models.TransactionStatus)
|
||||
deleted := new(models.TransactionStatus)
|
||||
completed := new(model.TransactionStatus)
|
||||
pending := new(model.TransactionStatus)
|
||||
deleted := new(model.TransactionStatus)
|
||||
|
||||
completed.Init()
|
||||
completed.Name = "Completed"
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,15 +14,16 @@ import (
|
||||
CreateTableApi
|
||||
|
||||
Creates api table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableApi(db pg.DB) error {
|
||||
|
||||
models := []interface{}{
|
||||
(*models.ApiModel)(nil),
|
||||
(*model.ApiModel)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
CreateTableUsers
|
||||
|
||||
Creates users table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableUsers(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.User)(nil),
|
||||
(*model.User)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
CreateTableWallets
|
||||
|
||||
Creates wallets table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableWallets(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.Wallet)(nil),
|
||||
(*model.Wallet)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
CreateTableTransactionTypes
|
||||
|
||||
Creates transaction_types table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableTransactionTypes(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.TransactionType)(nil),
|
||||
(*model.TransactionType)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
CreateTableTransactions
|
||||
|
||||
Creates transactions table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableTransactions(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.Transaction)(nil),
|
||||
(*model.Transaction)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
CreateTableSubscriptionTypes
|
||||
|
||||
Creates subscription_types table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableSubscriptionTypes(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.SubscriptionType)(nil),
|
||||
(*model.SubscriptionType)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
@@ -13,14 +13,15 @@ import (
|
||||
CreateTableSubscriptions
|
||||
|
||||
Creates subscriptions table if it does not exist.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with table creation
|
||||
*/
|
||||
func CreateTableSubscriptions(db pg.DB) error {
|
||||
models := []interface{}{
|
||||
(*models.Subscription)(nil),
|
||||
(*model.Subscription)(nil),
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
@@ -12,16 +12,17 @@ import (
|
||||
PopulateSubscriptionTypes
|
||||
|
||||
Populates subscription_types table if it exists.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
*/
|
||||
func PopulateSubscriptionTypes(db pg.DB) error {
|
||||
daily := new(models.SubscriptionType)
|
||||
weekly := new(models.SubscriptionType)
|
||||
monthly := new(models.SubscriptionType)
|
||||
yearly := new(models.SubscriptionType)
|
||||
daily := new(model.SubscriptionType)
|
||||
weekly := new(model.SubscriptionType)
|
||||
monthly := new(model.SubscriptionType)
|
||||
yearly := new(model.SubscriptionType)
|
||||
|
||||
daily.Init()
|
||||
daily.Name = "Daily"
|
||||
|
||||
@@ -3,7 +3,7 @@ package migrate
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
@@ -12,14 +12,15 @@ import (
|
||||
PopulateTransactionTypes
|
||||
|
||||
Populates transaction_types table if it exists.
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
|
||||
Args:
|
||||
*pg.DB: Postgres database client
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
*/
|
||||
func PopulateTransactionTypes(db pg.DB) error {
|
||||
gain := new(models.TransactionType)
|
||||
expense := new(models.TransactionType)
|
||||
gain := new(model.TransactionType)
|
||||
expense := new(model.TransactionType)
|
||||
|
||||
gain.Init()
|
||||
gain.Name = "Gain"
|
||||
|
||||
@@ -13,7 +13,7 @@ Starts database migration.
|
||||
Returns:
|
||||
error: Returns if there is an error with populating table
|
||||
*/
|
||||
func Start(conn *pg.DB, version string) {
|
||||
func Start(conn *pg.DB, version string) []error {
|
||||
migration001 := Migration{
|
||||
Version: "001",
|
||||
Migrations: []interface{}{
|
||||
@@ -53,16 +53,23 @@ func Start(conn *pg.DB, version string) {
|
||||
migration004,
|
||||
}
|
||||
|
||||
var errors []error
|
||||
|
||||
for _, migrationCol := range migrationsMap {
|
||||
if version != "" && version == migrationCol.Version || version == "" {
|
||||
for _, migration := range migrationCol.Migrations {
|
||||
mgFunc, isFunc := migration.(func(pg.DB) error)
|
||||
if isFunc {
|
||||
mgFunc(*conn)
|
||||
err := mgFunc(*conn)
|
||||
if err != nil {
|
||||
errors = append(errors, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
type Migration struct {
|
||||
|
||||
Reference in New Issue
Block a user