Skip to content

feat: add notifications inbox db #16599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
90c7b64
work on db queries
defelmnq Feb 18, 2025
e205049
work on dbauthz
defelmnq Feb 19, 2025
ef91969
work on dbauthz
defelmnq Feb 19, 2025
72e6de4
fmt and lint
defelmnq Feb 19, 2025
9edb384
change queries to match targets
defelmnq Feb 20, 2025
dc74ac4
test dbauthz
defelmnq Feb 20, 2025
6c9e41f
move notification migration
defelmnq Feb 20, 2025
1f18eca
make gen
defelmnq Feb 20, 2025
d02609f
Merge remote-tracking branch 'origin/main' into notif-inbox/int-334
defelmnq Feb 20, 2025
3bb9c57
rename inbox notifications
defelmnq Feb 20, 2025
27c1592
rename inbox notifications
defelmnq Feb 20, 2025
08c55c3
Improve authz
defelmnq Feb 21, 2025
b441448
add references in db
defelmnq Feb 21, 2025
1814c58
fix test icon
defelmnq Feb 21, 2025
9f46f51
improve foreign keys
defelmnq Feb 21, 2025
ddc65e6
add back querier file
defelmnq Feb 21, 2025
d1ce11e
improve uuid in seeding
defelmnq Feb 21, 2025
1f2fa24
improve dbauthz testing
defelmnq Feb 21, 2025
791ed76
format migration
defelmnq Feb 21, 2025
e141354
format migration
defelmnq Feb 21, 2025
a14723b
format migration
defelmnq Feb 21, 2025
e413ab9
rename functions
defelmnq Feb 21, 2025
452583e
add back index
defelmnq Feb 21, 2025
5aa54e1
fix query name missing
defelmnq Feb 21, 2025
da56e8f
regen file
defelmnq Feb 21, 2025
30b5ac4
add count queries
defelmnq Feb 23, 2025
8230ef3
improve queries to add pagination
defelmnq Feb 23, 2025
783bfe0
fix dbauthz tests
defelmnq Feb 23, 2025
c5aa917
fix sqlc queries
defelmnq Feb 23, 2025
da50947
improve dbauthz testing
defelmnq Feb 23, 2025
c1da7f8
improve sql queries
defelmnq Feb 24, 2025
f03976c
add type for read status
defelmnq Feb 24, 2025
94763e8
iterate on testing dbauthz
defelmnq Feb 24, 2025
0c5d322
change zero value of timestamp
defelmnq Feb 24, 2025
66d6fd6
add returns check in tests
defelmnq Feb 25, 2025
c45dfce
Merge remote-tracking branch 'origin/main' into notif-inbox/int-334
defelmnq Feb 25, 2025
b54dbef
rename migration
defelmnq Feb 25, 2025
e2e895b
improve queries comments
defelmnq Feb 25, 2025
e6abcbd
cange type for read status
defelmnq Feb 25, 2025
f691cf5
merge
defelmnq Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
work on db queries
  • Loading branch information
defelmnq committed Feb 20, 2025
commit 90c7b64a84edf24c0968daa22522193958dd6c60
24 changes: 24 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,14 @@ func (q *querier) FavoriteWorkspace(ctx context.Context, id uuid.UUID) error {
return update(q.log, q.auth, fetch, q.db.FavoriteWorkspace)(ctx, id)
}

func (q *querier) FetchInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *querier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *querier) FetchMemoryResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) (database.WorkspaceAgentMemoryResourceMonitor, error) {
workspace, err := q.db.GetWorkspaceByAgentID(ctx, agentID)
if err != nil {
Expand All @@ -1438,6 +1446,14 @@ func (q *querier) FetchNewMessageMetadata(ctx context.Context, arg database.Fetc
return q.db.FetchNewMessageMetadata(ctx, arg)
}

func (q *querier) FetchUnreadInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *querier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *querier) FetchVolumesResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
workspace, err := q.db.GetWorkspaceByAgentID(ctx, agentID)
if err != nil {
Expand Down Expand Up @@ -3077,6 +3093,10 @@ func (q *querier) InsertGroupMember(ctx context.Context, arg database.InsertGrou
return update(q.log, q.auth, fetch, q.db.InsertGroupMember)(ctx, arg)
}

func (q *querier) InsertInboxNotification(ctx context.Context, arg database.InsertInboxNotificationParams) (database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *querier) InsertLicense(ctx context.Context, arg database.InsertLicenseParams) (database.License, error) {
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceLicense); err != nil {
return database.License{}, err
Expand Down Expand Up @@ -3564,6 +3584,10 @@ func (q *querier) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string)
return q.db.RevokeDBCryptKey(ctx, activeKeyDigest)
}

func (q *querier) SetInboxNotificationAsRead(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
panic("not implemented")
}

func (q *querier) TryAcquireLock(ctx context.Context, id int64) (bool, error) {
return q.db.TryAcquireLock(ctx, id)
}
Expand Down
44 changes: 44 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,19 @@ func (q *FakeQuerier) FavoriteWorkspace(_ context.Context, arg uuid.UUID) error
return nil
}

func (q *FakeQuerier) FetchInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *FakeQuerier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
err := validateDatabaseType(arg)
if err != nil {
return nil, err
}

panic("not implemented")
}

func (q *FakeQuerier) FetchMemoryResourceMonitorsByAgentID(_ context.Context, agentID uuid.UUID) (database.WorkspaceAgentMemoryResourceMonitor, error) {
for _, monitor := range q.workspaceAgentMemoryResourceMonitors {
if monitor.AgentID == agentID {
Expand Down Expand Up @@ -2405,6 +2418,19 @@ func (q *FakeQuerier) FetchNewMessageMetadata(_ context.Context, arg database.Fe
}, nil
}

func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
panic("not implemented")
}

func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
err := validateDatabaseType(arg)
if err != nil {
return nil, err
}

panic("not implemented")
}

func (q *FakeQuerier) FetchVolumesResourceMonitorsByAgentID(_ context.Context, agentID uuid.UUID) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
monitors := []database.WorkspaceAgentVolumeResourceMonitor{}

Expand Down Expand Up @@ -7959,6 +7985,15 @@ func (q *FakeQuerier) InsertGroupMember(_ context.Context, arg database.InsertGr
return nil
}

func (q *FakeQuerier) InsertInboxNotification(ctx context.Context, arg database.InsertInboxNotificationParams) (database.NotificationsInbox, error) {
err := validateDatabaseType(arg)
if err != nil {
return database.NotificationsInbox{}, err
}

panic("not implemented")
}

func (q *FakeQuerier) InsertLicense(
_ context.Context, arg database.InsertLicenseParams,
) (database.License, error) {
Expand Down Expand Up @@ -9443,6 +9478,15 @@ func (q *FakeQuerier) RevokeDBCryptKey(_ context.Context, activeKeyDigest string
return sql.ErrNoRows
}

func (q *FakeQuerier) SetInboxNotificationAsRead(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
err := validateDatabaseType(arg)
if err != nil {
return err
}

panic("not implemented")
}

func (*FakeQuerier) TryAcquireLock(_ context.Context, _ int64) (bool, error) {
return false, xerrors.New("TryAcquireLock must only be called within a transaction")
}
Expand Down
42 changes: 42 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS notifications_inbox;
15 changes: 15 additions & 0 deletions coderd/database/migrations/000295_notifications_inbox.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE notifications_inbox (
id UUID PRIMARY KEY,
user_id UUID NOT NULL,
template_id UUID NOT NULL,
target_id UUID,
title TEXT NOT NULL,
content TEXT NOT NULL,
icon TEXT NOT NULL,
actions JSONB NOT NULL,
read_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_notifications_inbox_user_id_read_at ON notifications_inbox(user_id, read_at);
CREATE INDEX idx_notifications_inbox_user_id_template_id_target_id ON notifications_inbox(user_id, template_id, target_id);
13 changes: 13 additions & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading