Skip to content

Commit 8e8adbc

Browse files
Copilotdkhalife
andauthored
Replace PostgreSQL array types with JSON serialization for MariaDB compatibility (#215)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: dkhalife <[email protected]>
1 parent 4fa3b57 commit 8e8adbc

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

apiserver/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ require (
5454
github.com/json-iterator/go v1.1.12 // indirect
5555
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
5656
github.com/leodido/go-urn v1.4.0 // indirect
57-
github.com/lib/pq v1.10.9
5857
github.com/magiconair/properties v1.8.7 // indirect
5958
github.com/mattn/go-isatty v0.0.20 // indirect
6059
github.com/mitchellh/mapstructure v1.5.0 // indirect

apiserver/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
7575
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
7676
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
7777
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
78-
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
79-
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
8078
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
8179
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
8280
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=

apiserver/internal/models/recurrence.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package models
22

3-
import (
4-
"github.com/lib/pq"
5-
)
6-
73
type FrequencyType string
84

95
const (
@@ -38,6 +34,6 @@ type Frequency struct {
3834
On RepeatOn `json:"on" validate:"required_if=Type interval custom" gorm:"type:varchar(18);default:null"`
3935
Every int `json:"every" validate:"required_if=On interval" gorm:"type:int;default:null"`
4036
Unit IntervalUnit `json:"unit" validate:"required_if=On interval" gorm:"type:varchar(9);default:null"`
41-
Days pq.Int32Array `json:"days" validate:"required_if=Type custom On days_of_the_week,dive,gte=0,lte=6" gorm:"type:integer[];default:null"`
42-
Months pq.Int32Array `json:"months" validate:"required_if=Type custom On day_of_the_months,dive,gte=0,lte=11" gorm:"type:integer[];default:null"`
37+
Days []int32 `json:"days" validate:"required_if=Type custom On days_of_the_week,dive,gte=0,lte=6" gorm:"serializer:json;type:json"`
38+
Months []int32 `json:"months" validate:"required_if=Type custom On day_of_the_months,dive,gte=0,lte=11" gorm:"serializer:json;type:json"`
4339
}

apiserver/internal/models/user.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package models
22

33
import (
44
"time"
5-
6-
"github.com/lib/pq"
75
)
86

97
type User struct {
@@ -58,14 +56,14 @@ const (
5856
)
5957

6058
type AppToken struct {
61-
ID int `json:"id" gorm:"primary_key"`
62-
UserID int `json:"user_id" gorm:"column:user_id;not null"`
63-
Name string `json:"name" gorm:"column:name;not null"`
64-
Token string `json:"token" gorm:"column:token;index;not null"`
65-
Scopes pq.StringArray `json:"scopes" gorm:"column:scopes;type:text[]"`
66-
CreatedAt time.Time `json:"-" gorm:"column:created_at;default:CURRENT_TIMESTAMP"`
67-
ExpiresAt time.Time `json:"expires_at" gorm:"column:expires_at;default:CURRENT_TIMESTAMP"`
68-
User User `json:"-" gorm:"foreignKey:UserID"`
59+
ID int `json:"id" gorm:"primary_key"`
60+
UserID int `json:"user_id" gorm:"column:user_id;not null"`
61+
Name string `json:"name" gorm:"column:name;not null"`
62+
Token string `json:"token" gorm:"column:token;index;not null"`
63+
Scopes []string `json:"scopes" gorm:"column:scopes;serializer:json;type:json"`
64+
CreatedAt time.Time `json:"-" gorm:"column:created_at;default:CURRENT_TIMESTAMP"`
65+
ExpiresAt time.Time `json:"expires_at" gorm:"column:expires_at;default:CURRENT_TIMESTAMP"`
66+
User User `json:"-" gorm:"foreignKey:UserID"`
6967
}
7068

7169
type CreateAppTokenRequest struct {

apiserver/internal/repos/user/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"dkhalife.com/tasks/core/internal/models"
1010
"dkhalife.com/tasks/core/internal/utils/auth"
1111
"github.com/golang-jwt/jwt/v4"
12-
"github.com/lib/pq"
1312
"gorm.io/gorm"
1413
)
1514

@@ -157,7 +156,7 @@ func convertScopesToStringArray(scopes []models.ApiTokenScope) []string {
157156
strScopes[i] = string(scope)
158157
}
159158

160-
return pq.StringArray(strScopes)
159+
return strScopes
161160
}
162161

163162
func (r *UserRepository) CreateAppToken(c context.Context, userID int, name string, scopes []models.ApiTokenScope, days int) (*models.AppToken, error) {

apiserver/internal/repos/user/user_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"dkhalife.com/tasks/core/config"
99
"dkhalife.com/tasks/core/internal/models"
1010
"dkhalife.com/tasks/core/internal/utils/test"
11-
"github.com/lib/pq"
1211
"github.com/stretchr/testify/suite"
1312
)
1413

@@ -318,15 +317,15 @@ func (s *UserTestSuite) TestGetAllUserTokens() {
318317
Name: "Token 1",
319318
Token: "token1",
320319
ExpiresAt: time.Now().Add(24 * time.Hour),
321-
Scopes: pq.StringArray{"task:read"},
320+
Scopes: []string{"task:read"},
322321
}
323322

324323
token2 := &models.AppToken{
325324
UserID: testUser.ID,
326325
Name: "Token 2",
327326
Token: "token2",
328327
ExpiresAt: time.Now().Add(48 * time.Hour),
329-
Scopes: pq.StringArray{"task:write"},
328+
Scopes: []string{"task:write"},
330329
}
331330

332331
err = s.DB.Create(token1).Error
@@ -362,7 +361,7 @@ func (s *UserTestSuite) TestDeleteAppToken() {
362361
Name: "Test Token",
363362
Token: "token123",
364363
ExpiresAt: time.Now().Add(24 * time.Hour),
365-
Scopes: pq.StringArray{"task:read"},
364+
Scopes: []string{"task:read"},
366365
}
367366

368367
err = s.DB.Create(token).Error

0 commit comments

Comments
 (0)