Skip to content

Commit 1fe0d65

Browse files
committed
feat: add support for planetscale
Resolves #195
1 parent bfaa0f9 commit 1fe0d65

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

server/constants/db_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ const (
2323
DbTypeScyllaDB = "scylladb"
2424
// DbTypeCockroachDB is the cockroach database type
2525
DbTypeCockroachDB = "cockroachdb"
26+
// DbTypePlanetScaleDB is the planetscale database type
27+
DbTypePlanetScaleDB = "planetscale"
2628
)

server/db/models/session.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ package models
66
type Session struct {
77
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty"` // for arangodb
88
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id"`
9-
UserID string `gorm:"type:char(36),index:" json:"user_id" bson:"user_id" cql:"user_id"`
10-
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" bson:"-" cql:"-"`
9+
UserID string `gorm:"type:char(36)" json:"user_id" bson:"user_id" cql:"user_id"`
1110
UserAgent string `json:"user_agent" bson:"user_agent" cql:"user_agent"`
1211
IP string `json:"ip" bson:"ip" cql:"ip"`
1312
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`

server/db/models/webhook_log.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import "github.com/authorizerdev/authorizer/server/graph/model"
66

77
// WebhookLog model for db
88
type WebhookLog struct {
9-
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty"` // for arangodb
10-
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id"`
11-
HttpStatus int64 `json:"http_status" bson:"http_status" cql:"http_status"`
12-
Response string `gorm:"type:text" json:"response" bson:"response" cql:"response"`
13-
Request string `gorm:"type:text" json:"request" bson:"request" cql:"request"`
14-
WebhookID string `gorm:"type:char(36),index:" json:"webhook_id" bson:"webhook_id" cql:"webhook_id"`
15-
Webhook Webhook `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" bson:"-" cql:"-"`
16-
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
17-
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
9+
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty"` // for arangodb
10+
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id"`
11+
HttpStatus int64 `json:"http_status" bson:"http_status" cql:"http_status"`
12+
Response string `gorm:"type:text" json:"response" bson:"response" cql:"response"`
13+
Request string `gorm:"type:text" json:"request" bson:"request" cql:"request"`
14+
WebhookID string `gorm:"type:char(36)" json:"webhook_id" bson:"webhook_id" cql:"webhook_id"`
15+
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
16+
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
1817
}
1918

2019
func (w *WebhookLog) AsAPIWebhookLog() *model.WebhookLog {

server/db/providers/sql/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewProvider() (*provider, error) {
5050
sqlDB, err = gorm.Open(postgres.Open(dbURL), ormConfig)
5151
case constants.DbTypeSqlite:
5252
sqlDB, err = gorm.Open(sqlite.Open(dbURL), ormConfig)
53-
case constants.DbTypeMysql, constants.DbTypeMariaDB:
53+
case constants.DbTypeMysql, constants.DbTypeMariaDB, constants.DbTypePlanetScaleDB:
5454
sqlDB, err = gorm.Open(mysql.Open(dbURL), ormConfig)
5555
case constants.DbTypeSqlserver:
5656
sqlDB, err = gorm.Open(sqlserver.Open(dbURL), ormConfig)

server/resolvers/delete_user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod
4545
return res, err
4646
}
4747

48+
err = db.Provider.DeleteSession(ctx, user.ID)
49+
if err != nil {
50+
return res, err
51+
}
52+
4853
res = &model.Response{
4954
Message: `user deleted successfully`,
5055
}

0 commit comments

Comments
 (0)