Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit154bec5

Browse files
committed
join on extra columns
1 parenta1302bd commit154bec5

File tree

11 files changed

+160
-63
lines changed

11 files changed

+160
-63
lines changed

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,13 @@ func (s *MethodTestSuite) TestConnectionLogs() {
357357
}))
358358
s.Run("GetConnectionLogsOffset",s.Subtest(func(db database.Store,check*expects) {
359359
ws:=createWorkspace(s.T(),db)
360-
_=dbgen.ConnectionLog(s.T(),db, database.ConnectionLog{
360+
_=dbgen.ConnectionLog(s.T(),db, database.UpsertConnectionLogParams{
361361
Type:database.ConnectionTypeSsh,
362362
WorkspaceID:ws.ID,
363363
OrganizationID:ws.OrganizationID,
364364
WorkspaceOwnerID:ws.OwnerID,
365365
})
366-
_=dbgen.ConnectionLog(s.T(),db, database.ConnectionLog{
366+
_=dbgen.ConnectionLog(s.T(),db, database.UpsertConnectionLogParams{
367367
Type:database.ConnectionTypeSsh,
368368
WorkspaceID:ws.ID,
369369
OrganizationID:ws.OrganizationID,
@@ -375,13 +375,13 @@ func (s *MethodTestSuite) TestConnectionLogs() {
375375
}))
376376
s.Run("GetAuthorizedConnectionLogsOffset",s.Subtest(func(db database.Store,check*expects) {
377377
ws:=createWorkspace(s.T(),db)
378-
_=dbgen.ConnectionLog(s.T(),db, database.ConnectionLog{
378+
_=dbgen.ConnectionLog(s.T(),db, database.UpsertConnectionLogParams{
379379
Type:database.ConnectionTypeSsh,
380380
WorkspaceID:ws.ID,
381381
OrganizationID:ws.OrganizationID,
382382
WorkspaceOwnerID:ws.OwnerID,
383383
})
384-
_=dbgen.ConnectionLog(s.T(),db, database.ConnectionLog{
384+
_=dbgen.ConnectionLog(s.T(),db, database.UpsertConnectionLogParams{
385385
Type:database.ConnectionTypeSsh,
386386
WorkspaceID:ws.ID,
387387
OrganizationID:ws.OrganizationID,

‎coderd/database/dbgen/dbgen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func AuditLog(t testing.TB, db database.Store, seed database.AuditLog) database.
7373
returnlog
7474
}
7575

76-
funcConnectionLog(t testing.TB,db database.Store,seed database.ConnectionLog) database.ConnectionLog {
76+
funcConnectionLog(t testing.TB,db database.Store,seed database.UpsertConnectionLogParams) database.ConnectionLog {
7777
log,err:=db.UpsertConnectionLog(genCtx, database.UpsertConnectionLogParams{
7878
ID:takeFirst(seed.ID,uuid.New()),
7979
Time:takeFirst(seed.Time,dbtime.Now()),
@@ -111,7 +111,7 @@ func ConnectionLog(t testing.TB, db database.Store, seed database.ConnectionLog)
111111
String:takeFirst(seed.CloseReason.String,""),
112112
Valid:takeFirst(seed.CloseReason.Valid,false),
113113
},
114-
ConnectionStatus:database.ConnectionStatusConnected,
114+
ConnectionStatus:takeFirst(seed.ConnectionStatus,database.ConnectionStatusConnected),
115115
})
116116
require.NoError(t,err,"insert connection log")
117117
returnlog

‎coderd/database/dbmem/dbmem.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13951,9 +13951,51 @@ func (q *FakeQuerier) GetAuthorizedConnectionLogsOffset(ctx context.Context, arg
1395113951
continue
1395213952
}
1395313953

13954+
workspaceOwner,err:=q.getUserByIDNoLock(clog.WorkspaceOwnerID)
13955+
iferr!=nil {
13956+
continue// JOIN on workspace_owner failed
13957+
}
13958+
org,err:=q.getOrganizationByIDNoLock(clog.OrganizationID)
13959+
iferr!=nil {
13960+
continue// JOIN on organizations failed
13961+
}
13962+
workspace,err:=q.getWorkspaceByIDNoLock(ctx,clog.WorkspaceID)
13963+
iferr!=nil {
13964+
continue// JOIN on workspaces failed
13965+
}
13966+
13967+
// LEFT JOIN on users
13968+
varuser database.User
13969+
varuserErrerror
13970+
ifclog.UserID.Valid {
13971+
user,userErr=q.getUserByIDNoLock(clog.UserID.UUID)
13972+
}
13973+
userValid:=clog.UserID.Valid&&userErr==nil
13974+
13975+
// Append the fully hydrated row
1395413976
logs=append(logs, database.GetConnectionLogsOffsetRow{
13955-
ConnectionLog:clog,
13977+
ConnectionLog:clog,
13978+
WorkspaceDeleted:workspace.Deleted,
13979+
WorkspaceOwnerUsername:workspaceOwner.Username,
13980+
OrganizationName:org.Name,
13981+
OrganizationDisplayName:org.DisplayName,
13982+
OrganizationIcon:org.Icon,
13983+
UserUsername: sql.NullString{String:user.Username,Valid:userValid},
13984+
UserName: sql.NullString{String:user.Name,Valid:userValid},
13985+
UserEmail: sql.NullString{String:user.Email,Valid:userValid},
13986+
UserCreatedAt: sql.NullTime{Time:user.CreatedAt,Valid:userValid},
13987+
UserUpdatedAt: sql.NullTime{Time:user.UpdatedAt,Valid:userValid},
13988+
UserLastSeenAt: sql.NullTime{Time:user.LastSeenAt,Valid:userValid},
13989+
UserStatus: database.NullUserStatus{UserStatus:user.Status,Valid:userValid},
13990+
UserLoginType: database.NullLoginType{LoginType:user.LoginType,Valid:userValid},
13991+
UserRoles:user.RBACRoles,
13992+
UserAvatarUrl: sql.NullString{String:user.AvatarURL,Valid:userValid},
13993+
UserDeleted: sql.NullBool{Bool:user.Deleted,Valid:userValid},
13994+
UserQuietHoursSchedule: sql.NullString{String:user.QuietHoursSchedule,Valid:userValid},
13995+
Count:0,// Will be set after the loop.
1395613996
})
13997+
13998+
// Apply LIMIT, same as the audit log implementation.
1395713999
iflen(logs)>=int(arg.LimitOpt) {
1395814000
break
1395914001
}

‎coderd/database/dump.sql

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000336_connection_logs.up.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CREATE TABLE connection_logs (
2222
workspace_nametextNOT NULL,
2323
agent_nametextNOT NULL,
2424
type connection_typeNOT NULL,
25-
codeinteger,-- Null until we upsert a disconnected log for the same connection_id.
25+
codeinteger,
2626
ipinet,
2727

2828
-- Only set for 'web' logs.
@@ -32,14 +32,14 @@ CREATE TABLE connection_logs (
3232

3333
-- Null for 'web' logs.
3434
connection_id uuid,
35-
close_timetimestamp with time zone,-- Null until we upsert adisconnected log for the same connection_id.
35+
close_timetimestamp with time zone,-- Null until we upsert adisconnect log for the same connection_id.
3636
close_reasontext,
3737

3838
PRIMARY KEY (id)
3939
);
4040

4141

42-
COMMENT ON COLUMN connection_logs.code IS'Either the HTTP status code of the web request, or the exit code of an SSH connection. ForSSH actions, this is Nullif the connection is still open, or if we never received a disconnect log..';
42+
COMMENT ON COLUMN connection_logs.code IS'Either the HTTP status code of the web request, or the exit code of an SSH connection. Fornon-web connections, this is Nulluntil we receive a disconnect event for the same connection_id.';
4343

4444
COMMENT ON COLUMN connection_logs.user_agent IS'Null for SSH actions. For web connections, this is the User-Agent header from the request.';
4545

@@ -49,9 +49,9 @@ COMMENT ON COLUMN connection_logs.slug_or_port IS 'Null for SSH actions. For web
4949

5050
COMMENT ON COLUMN connection_logs.connection_id IS'The SSH connection ID. Used to correlate connections and disconnections. As it originates from the agent, it is not guaranteed to be unique.';
5151

52-
COMMENT ON COLUMN connection_logs.close_time IS'Null for web connections. ForSSH actions, Nulluntil we receive asecond event for the same connection_id. This is the time when the connection was closed.';
52+
COMMENT ON COLUMN connection_logs.close_time IS'The time the connection was closed.Null for web connections. Forother connections, this is nulluntil we receive adisconnect event for the same connection_id.';
5353

54-
COMMENT ON COLUMN connection_logs.close_reason IS'Null for web connections. ForSSH actions, this isthe reason for the connection or disconnection, to be displayed intheUI.';
54+
COMMENT ON COLUMN connection_logs.close_reason IS'The reason the connection was closed.Null for web connections. Forother connections, this isnull until we receive a disconnect event forthesame connection_id.';
5555

5656
COMMENT ON TYPE audit_action IS'NOTE: `connect`, `disconnect`, `open`, and `close` are deprecated and no longer used - these events are now tracked in the connection_logs table.';
5757

‎coderd/database/modelqueries.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,23 @@ func (q *sqlQuerier) GetAuthorizedConnectionLogsOffset(ctx context.Context, arg
576576
&i.ConnectionLog.ConnectionID,
577577
&i.ConnectionLog.CloseTime,
578578
&i.ConnectionLog.CloseReason,
579+
&i.WorkspaceDeleted,
579580
&i.UserUsername,
581+
&i.UserName,
582+
&i.UserEmail,
583+
&i.UserCreatedAt,
584+
&i.UserUpdatedAt,
585+
&i.UserLastSeenAt,
586+
&i.UserStatus,
587+
&i.UserLoginType,
588+
&i.UserRoles,
589+
&i.UserAvatarUrl,
590+
&i.UserDeleted,
591+
&i.UserQuietHoursSchedule,
580592
&i.WorkspaceOwnerUsername,
593+
&i.OrganizationName,
594+
&i.OrganizationDisplayName,
595+
&i.OrganizationIcon,
581596
&i.Count,
582597
);err!=nil {
583598
returnnil,err

‎coderd/database/models.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
20882088
}
20892089
fororgID,ids:=rangeorgConnectionLogs {
20902090
for_,id:=rangeids {
2091-
allLogs=append(allLogs,dbgen.ConnectionLog(t,authDb, database.ConnectionLog{
2091+
allLogs=append(allLogs,dbgen.ConnectionLog(t,authDb, database.UpsertConnectionLogParams{
20922092
WorkspaceID:wsID,
20932093
WorkspaceOwnerID:user.ID,
20942094
ID:id,

‎coderd/database/queries.sql.go

Lines changed: 59 additions & 7 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/connectionlogs.sql

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
-- name: GetConnectionLogsOffset :many
22
SELECT
33
sqlc.embed(connection_logs),
4-
users.usernameAS user_username,
4+
workspaces.deletedAS workspace_deleted,
5+
-- sqlc.embed(users) would be nice but it does not seem to play well with
6+
-- left joins. This user metadata is necessary for parity with the audit logs
7+
-- API.
8+
users.usernameAS user_username,
9+
users.nameAS user_name,
10+
users.emailAS user_email,
11+
users.created_atAS user_created_at,
12+
users.updated_atAS user_updated_at,
13+
users.last_seen_atAS user_last_seen_at,
14+
users.statusAS user_status,
15+
users.login_typeAS user_login_type,
16+
users.rbac_rolesAS user_roles,
17+
users.avatar_urlAS user_avatar_url,
18+
users.deletedAS user_deleted,
19+
users.quiet_hours_scheduleAS user_quiet_hours_schedule,
520
workspace_owner.usernameAS workspace_owner_username,
21+
organizations.nameas organization_name,
22+
organizations.display_nameas organization_display_name,
23+
organizations.iconas organization_icon,
624
COUNT(connection_logs.*) OVER ()AS count
725
FROM
826
connection_logs
27+
JOIN usersAS workspace_ownerON
28+
connection_logs.workspace_owner_id=workspace_owner.id
929
LEFT JOIN usersON
1030
connection_logs.user_id=users.id
11-
LEFT JOIN usersas workspace_ownerON
12-
connection_logs.workspace_owner_id=workspace_owner.id
31+
JOIN organizationsON
32+
connection_logs.organization_id=organizations.id
33+
JOIN workspacesON
34+
connection_logs.workspace_id=workspaces.id
1335
WHERE TRUE
1436
-- Authorize Filter clause will be injected below in
1537
-- GetAuthorizedConnectionLogsOffset

‎codersdk/agentsdk/convert.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -408,40 +408,6 @@ func ProtoFromLifecycleState(s codersdk.WorkspaceAgentLifecycle) (proto.Lifecycl
408408
returnproto.Lifecycle_State(caps),nil
409409
}
410410

411-
funcConnectionTypeFromProto(typ proto.Connection_Type) (ConnectionType,error) {
412-
switchtyp {
413-
caseproto.Connection_TYPE_UNSPECIFIED:
414-
returnConnectionTypeUnspecified,nil
415-
caseproto.Connection_SSH:
416-
returnConnectionTypeSSH,nil
417-
caseproto.Connection_VSCODE:
418-
returnConnectionTypeVSCode,nil
419-
caseproto.Connection_JETBRAINS:
420-
returnConnectionTypeJetBrains,nil
421-
caseproto.Connection_RECONNECTING_PTY:
422-
returnConnectionTypeReconnectingPTY,nil
423-
default:
424-
return"",xerrors.Errorf("unknown connection type %q",typ)
425-
}
426-
}
427-
428-
funcProtoFromConnectionType(typConnectionType) (proto.Connection_Type,error) {
429-
switchtyp {
430-
caseConnectionTypeUnspecified:
431-
returnproto.Connection_TYPE_UNSPECIFIED,nil
432-
caseConnectionTypeSSH:
433-
returnproto.Connection_SSH,nil
434-
caseConnectionTypeVSCode:
435-
returnproto.Connection_VSCODE,nil
436-
caseConnectionTypeJetBrains:
437-
returnproto.Connection_JETBRAINS,nil
438-
caseConnectionTypeReconnectingPTY:
439-
returnproto.Connection_RECONNECTING_PTY,nil
440-
default:
441-
return0,xerrors.Errorf("unknown connection type %q",typ)
442-
}
443-
}
444-
445411
funcDevcontainersFromProto(pdcs []*proto.WorkspaceAgentDevcontainer) ([]codersdk.WorkspaceAgentDevcontainer,error) {
446412
ret:=make([]codersdk.WorkspaceAgentDevcontainer,len(pdcs))
447413
fori,pdc:=rangepdcs {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp