fix postgresql issues

This commit is contained in:
2023-05-08 01:16:08 +02:00
parent 9e2b9251db
commit 6ecc05ba0b
6 changed files with 52 additions and 3 deletions

View File

@@ -87,6 +87,6 @@ func (s MongoDBStorage) SubscribeIncentive(incentive_subscription IncentiveSubsc
return nil
}
func (psql MongoDBStorage) Migrate() error {
func (s MongoDBStorage) Migrate() error {
return nil
}

View File

@@ -57,10 +57,10 @@ func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
func (s PostgresqlStorage) GetUserSubscriptions(userid string) ([]IncentiveSubscription, error) {
req := fmt.Sprintf(`SELECT id, incentive_id, user_id, identity_verification_ids, data, declined, subscription_datetime
FROM %s
WHERE user_id=$1`, s.Tables["incentive_subscriptions"])
FROM %s WHERE user_id = $1`, s.Tables["incentive_subscriptions"])
rows, err := s.DbConnection.Query(req, userid)
if err != nil {
log.Error().Str("request", req).Err(err).Msg("GetUserSubscriptions query error")
return nil, err
}
defer rows.Close()

View File

@@ -15,6 +15,7 @@ table "incentive_subscriptions" {
column "identity_verification_ids" {
null = true
type = sql("text[]")
default = sql("array[]::text[]")
}
column "data" {
null = false
@@ -27,6 +28,7 @@ table "incentive_subscriptions" {
column "subscription_datetime" {
null = true
type = timestamptz
default = sql("now()")
}
primary_key {
columns = [column.id]

View File

@@ -22,6 +22,9 @@ func NewStorage(cfg *viper.Viper) (Storage, error) {
case "mongodb":
s, err := NewMongoDBStorage(cfg)
return s, err
case "psql":
s, err := NewPostgresqlStorage(cfg)
return s, err
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}