Skip to content

Commit 46bf1ef

Browse files
committed
Make user API compatible with postgres
1 parent 78165e6 commit 46bf1ef

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

backend/dbscripts/thunderdb/postgress.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Table to store Users
2-
CREATE TABLE USER (
2+
CREATE TABLE "USER" (
33
ID INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
44
USER_ID VARCHAR(36) UNIQUE NOT NULL,
55
ORG_ID VARCHAR(36) NOT NULL,
@@ -114,7 +114,7 @@ VALUES
114114
('550e8400-e29b-41d4-a716-446655440000', '550e8400-e29b-41d4-a716-446655440001', '550e8400-e29b-41d4-a716-446655440004'),
115115
('550e8400-e29b-41d4-a716-446655440000', '550e8400-e29b-41d4-a716-446655440002', '550e8400-e29b-41d4-a716-446655440005');
116116

117-
INSERT INTO USER (USER_ID, ORG_ID, TYPE, ATTRIBUTES, CREATED_AT, UPDATED_AT)
117+
INSERT INTO "USER" (USER_ID, ORG_ID, TYPE, ATTRIBUTES)
118118
VALUES
119119
('550e8400-e29b-41d4-a716-446655440000', '456e8400-e29b-41d4-a716-446655440001', 'person',
120120
'{"age": 30, "roles": ["admin", "user"], "address": {"city": "Colombo", "zip": "00100"}}');

backend/internal/user/store/constants.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import dbmodel "github.com/asgardeo/thunder/internal/system/database/model"
2323
var (
2424
QueryCreateUser = dbmodel.DBQuery{
2525
Id: "ASQ-USER_MGT-01",
26-
Query: "INSERT INTO USER (USER_ID, ORG_ID, TYPE, ATTRIBUTES) VALUES ($1, $2, $3, $4)",
26+
Query: "INSERT INTO \"USER\" (USER_ID, ORG_ID, TYPE, ATTRIBUTES) VALUES ($1, $2, $3, $4)",
2727
}
2828
QueryGetUserByUserId = dbmodel.DBQuery{
2929
Id: "ASQ-USER_MGT-02",
30-
Query: "SELECT USER_ID, ORG_ID, TYPE, ATTRIBUTES FROM USER WHERE USER_ID = $1",
30+
Query: "SELECT USER_ID, ORG_ID, TYPE, ATTRIBUTES FROM \"USER\" WHERE USER_ID = $1",
3131
}
3232
QueryGetUserList = dbmodel.DBQuery{
3333
Id: "ASQ-USER_MGT-03",
34-
Query: "SELECT USER_ID, ORG_ID, TYPE, ATTRIBUTES FROM USER",
34+
Query: "SELECT USER_ID, ORG_ID, TYPE, ATTRIBUTES FROM \"USER\"",
3535
}
3636
QueryUpdateUserByUserId = dbmodel.DBQuery{
3737
Id: "ASQ-USER_MGT-04",
38-
Query: "UPDATE USER SET ORG_ID = $2, TYPE = $3, ATTRIBUTES = $4 WHERE USER_ID = $1;",
38+
Query: "UPDATE \"USER\" SET ORG_ID = $2, TYPE = $3, ATTRIBUTES = $4 WHERE USER_ID = $1;",
3939
}
4040
QueryDeleteUserByUserId = dbmodel.DBQuery{
4141
Id: "ASQ-USER_MGT-05",
42-
Query: "DELETE FROM USER WHERE USER_ID = $1",
42+
Query: "DELETE FROM \"USER\" WHERE USER_ID = $1",
4343
}
4444
)

backend/internal/user/store/store.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,14 @@ func buildUserFromResultRow(row map[string]interface{}) (model.User, error) {
210210
return model.User{}, fmt.Errorf("failed to parse type as string")
211211
}
212212

213-
attributes, ok := row["attributes"].(string)
214-
if !ok {
215-
logger.Error("failed to parse attributes as string")
213+
var attributes string
214+
switch v := row["attributes"].(type) {
215+
case string:
216+
attributes = v
217+
case []byte:
218+
attributes = string(v) // Convert byte slice to string
219+
default:
220+
logger.Error("failed to parse attributes", log.Any("raw_value", row["attributes"]), log.String("type", fmt.Sprintf("%T", row["attributes"])))
216221
return model.User{}, fmt.Errorf("failed to parse attributes as string")
217222
}
218223

0 commit comments

Comments
 (0)