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

Commit88451a1

Browse files
committed
Only return UUID from EnqueueNotificationMessage
Changes made to dbgen are to avoid this panic:$ ./coderd/database/generate.shgeneratepanic: unknown return type: *dst.SelectorExprgoroutine 1 [running]:main.orderAndStubDatabaseFunctions({0x1400001ea80, 0x3c}, {0x102d019e0, 0x1}, {0x102d0bc75, 0xb}, 0x102df7b20) /Users/danny/Code/coder/coder/scripts/dbgen/main.go:367 +0x2588main.run() /Users/danny/Code/coder/coder/scripts/dbgen/main.go:56 +0x118main.main() /Users/danny/Code/coder/coder/scripts/dbgen/main.go:42 +0x1cexit status 2Signed-off-by: Danny Kopping <danny@coder.com>
1 parent5ff29c0 commit88451a1

File tree

9 files changed

+36
-39
lines changed

9 files changed

+36
-39
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,9 @@ func (q *querier) DeleteWorkspaceAgentPortSharesByTemplate(ctx context.Context,
11431143
returnq.db.DeleteWorkspaceAgentPortSharesByTemplate(ctx,templateID)
11441144
}
11451145

1146-
func (q*querier)EnqueueNotificationMessage(ctx context.Context,arg database.EnqueueNotificationMessageParams) (database.NotificationMessage,error) {
1146+
func (q*querier)EnqueueNotificationMessage(ctx context.Context,arg database.EnqueueNotificationMessageParams) (uuid.UUID,error) {
11471147
iferr:=q.authorizeContext(ctx,policy.ActionCreate,rbac.ResourceSystem);err!=nil {
1148-
returndatabase.NotificationMessage{},err
1148+
returnuuid.UUID{},err
11491149
}
11501150
returnq.db.EnqueueNotificationMessage(ctx,arg)
11511151
}

‎coderd/database/dbmem/dbmem.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,10 @@ func (q *FakeQuerier) DeleteWorkspaceAgentPortSharesByTemplate(_ context.Context
18171817
returnnil
18181818
}
18191819

1820-
func (q*FakeQuerier)EnqueueNotificationMessage(_ context.Context,arg database.EnqueueNotificationMessageParams) (database.NotificationMessage,error) {
1820+
func (q*FakeQuerier)EnqueueNotificationMessage(_ context.Context,arg database.EnqueueNotificationMessageParams) (uuid.UUID,error) {
18211821
err:=validateDatabaseType(arg)
18221822
iferr!=nil {
1823-
returndatabase.NotificationMessage{},err
1823+
returnuuid.UUID{},err
18241824
}
18251825

18261826
q.mutex.Lock()
@@ -1829,7 +1829,7 @@ func (q *FakeQuerier) EnqueueNotificationMessage(_ context.Context, arg database
18291829
varpayload types.MessagePayload
18301830
err=json.Unmarshal(arg.Payload,&payload)
18311831
iferr!=nil {
1832-
returndatabase.NotificationMessage{},err
1832+
returnuuid.UUID{},err
18331833
}
18341834

18351835
nm:= database.NotificationMessage{
@@ -1847,7 +1847,7 @@ func (q *FakeQuerier) EnqueueNotificationMessage(_ context.Context, arg database
18471847

18481848
q.notificationMessages=append(q.notificationMessages,nm)
18491849

1850-
returnnm,err
1850+
returnnm.ID,err
18511851
}
18521852

18531853
func (q*FakeQuerier)FavoriteWorkspace(_ context.Context,arg uuid.UUID)error {

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

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

‎coderd/database/queries/notifications.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ VALUES (@id,
1919
@payload::jsonb,
2020
@targets,
2121
@created_by)
22-
RETURNING*;
22+
RETURNINGid;
2323

2424
-- Acquires the lease for a given count of notification messages, to enable concurrent dequeuing and subsequent sending.
2525
-- Only rows that aren't already leased (or ones which are leased but have exceeded their lease period) are returned.

‎coderd/notifications/manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ func newEnqueueInterceptor(db notifications.Store, metadataFn func() database.Fe
219219
return&enqueueInterceptor{Store:db,payload:make(chan types.MessagePayload,1),metadataFn:metadataFn}
220220
}
221221

222-
func (e*enqueueInterceptor)EnqueueNotificationMessage(_ context.Context,arg database.EnqueueNotificationMessageParams) (database.NotificationMessage,error) {
222+
func (e*enqueueInterceptor)EnqueueNotificationMessage(_ context.Context,arg database.EnqueueNotificationMessageParams) (uuid.UUID,error) {
223223
varpayload types.MessagePayload
224224
err:=json.Unmarshal(arg.Payload,&payload)
225225
iferr!=nil {
226-
returndatabase.NotificationMessage{},err
226+
returnuuid.UUID{},err
227227
}
228228

229229
e.payload<-payload
230-
returndatabase.NotificationMessage{},err
230+
returnuuid.UUID{},err
231231
}
232232

233233
func (e*enqueueInterceptor)FetchNewMessageMetadata(_ context.Context,_ database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error) {

‎coderd/notifications/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Store interface {
1818
AcquireNotificationMessages(ctx context.Context,params database.AcquireNotificationMessagesParams) ([]database.AcquireNotificationMessagesRow,error)
1919
BulkMarkNotificationMessagesSent(ctx context.Context,arg database.BulkMarkNotificationMessagesSentParams) (int64,error)
2020
BulkMarkNotificationMessagesFailed(ctx context.Context,arg database.BulkMarkNotificationMessagesFailedParams) (int64,error)
21-
EnqueueNotificationMessage(ctx context.Context,arg database.EnqueueNotificationMessageParams) (database.NotificationMessage,error)
21+
EnqueueNotificationMessage(ctx context.Context,arg database.EnqueueNotificationMessageParams) (uuid.UUID,error)
2222
FetchNewMessageMetadata(ctx context.Context,arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error)
2323
GetNotificationMessagesByStatus(ctx context.Context,arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage,error)
2424
}

‎scripts/dbgen/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,22 @@ func orderAndStubDatabaseFunctions(filePath, receiver, structName string, stub f
342342
switchtyp:=r.Type.(type) {
343343
case*dst.StarExpr,*dst.ArrayType:
344344
returnStmt.Results=append(returnStmt.Results,dst.NewIdent("nil"))
345-
case*dst.Ident:
346-
iftyp.Path!="" {
347-
returnStmt.Results=append(returnStmt.Results,dst.NewIdent(fmt.Sprintf("%s.%s{}",path.Base(typ.Path),typ.Name)))
345+
case*dst.Ident,*dst.SelectorExpr:
346+
varident*dst.Ident
347+
348+
// SelectorExpr contains a *dst.Ident
349+
ifsel,ok:=typ.(*dst.SelectorExpr);ok {
350+
ifident,ok=sel.X.(*dst.Ident);!ok {
351+
panic(fmt.Sprintf("SelectorExpr does not contain expected type %T: got %T",ident,sel.X))
352+
}
353+
}else {
354+
ident=typ.(*dst.Ident)
355+
}
356+
357+
ifident.Path!="" {
358+
returnStmt.Results=append(returnStmt.Results,dst.NewIdent(fmt.Sprintf("%s.%s{}",path.Base(ident.Path),ident.Name)))
348359
}else {
349-
switchtyp.Name {
360+
switchident.Name {
350361
case"uint8","uint16","uint32","uint64","uint","uintptr",
351362
"int8","int16","int32","int64","int",
352363
"byte","rune",
@@ -359,8 +370,10 @@ func orderAndStubDatabaseFunctions(filePath, receiver, structName string, stub f
359370
returnStmt.Results=append(returnStmt.Results,dst.NewIdent("false"))
360371
case"error":
361372
returnStmt.Results=append(returnStmt.Results,dst.NewIdent("err"))
373+
case"uuid":
374+
returnStmt.Results=append(returnStmt.Results,dst.NewIdent("uuid"))
362375
default:
363-
panic(fmt.Sprintf("unknown ident: %#v",r.Type))
376+
panic(fmt.Sprintf("unknown ident (%q): %#v",ident.Name,r.Type))
364377
}
365378
}
366379
default:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp