Skip to content

Commit 9ba4c04

Browse files
committed
WIP
1 parent fdad745 commit 9ba4c04

File tree

13 files changed

+38
-53
lines changed

13 files changed

+38
-53
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,11 +1613,11 @@ func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg datab
16131613
return q.db.GetNotificationMessagesByStatus(ctx, arg)
16141614
}
16151615

1616-
func (q *querier) GetNotificationReportGeneratorLogByUserAndTemplate(ctx context.Context, arg database.GetNotificationReportGeneratorLogByUserAndTemplateParams) (database.NotificationReportGeneratorLog, error) {
1616+
func (q *querier) GetNotificationReportGeneratorLogByTemplate(ctx context.Context, arg uuid.UUID) (database.NotificationReportGeneratorLog, error) {
16171617
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
16181618
return database.NotificationReportGeneratorLog{}, err
16191619
}
1620-
return q.db.GetNotificationReportGeneratorLogByUserAndTemplate(ctx, arg)
1620+
return q.db.GetNotificationReportGeneratorLogByTemplate(ctx, arg)
16211621
}
16221622

16231623
func (q *querier) GetNotificationTemplateByID(ctx context.Context, id uuid.UUID) (database.NotificationTemplate, error) {

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,15 +2747,12 @@ func (s *MethodTestSuite) TestSystemFunctions() {
27472747
Since: dbtime.Now(),
27482748
}).Asserts(rbac.ResourceSystem, policy.ActionRead)
27492749
}))
2750-
s.Run("GetNotificationReportGeneratorLogByUserAndTemplate", s.Subtest(func(db database.Store, check *expects) {
2751-
u := dbgen.User(s.T(), db, database.User{})
2750+
s.Run("GetNotificationReportGeneratorLogByTemplate", s.Subtest(func(db database.Store, check *expects) {
27522751
_ = db.UpsertNotificationReportGeneratorLog(context.Background(), database.UpsertNotificationReportGeneratorLogParams{
2753-
UserID: u.ID,
27542752
NotificationTemplateID: notifications.TemplateWorkspaceBuildsFailedReport,
27552753
LastGeneratedAt: dbtime.Now(),
27562754
})
2757-
check.Args(database.GetNotificationReportGeneratorLogByUserAndTemplateParams{
2758-
UserID: u.ID,
2755+
check.Args(database.GetNotificationReportGeneratorLogByTemplateParams{
27592756
NotificationTemplateID: notifications.TemplateWorkspaceBuildsFailedReport,
27602757
}).Asserts(rbac.ResourceSystem, policy.ActionRead)
27612758
}))
@@ -2764,7 +2761,6 @@ func (s *MethodTestSuite) TestSystemFunctions() {
27642761
}))
27652762
s.Run("UpsertNotificationReportGeneratorLog", s.Subtest(func(db database.Store, check *expects) {
27662763
check.Args(database.UpsertNotificationReportGeneratorLogParams{
2767-
UserID: uuid.New(),
27682764
NotificationTemplateID: uuid.New(),
27692765
LastGeneratedAt: dbtime.Now(),
27702766
}).Asserts(rbac.ResourceSystem, policy.ActionCreate)

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,7 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
30023002
return out, nil
30033003
}
30043004

3005-
func (q *FakeQuerier) GetNotificationReportGeneratorLogByUserAndTemplate(_ context.Context, arg database.GetNotificationReportGeneratorLogByUserAndTemplateParams) (database.NotificationReportGeneratorLog, error) {
3005+
func (q *FakeQuerier) GetNotificationReportGeneratorLogByTemplate(_ context.Context, arg uuid.UUID) (database.NotificationReportGeneratorLog, error) {
30063006
err := validateDatabaseType(arg)
30073007
if err != nil {
30083008
return database.NotificationReportGeneratorLog{}, err
@@ -9384,7 +9384,7 @@ func (q *FakeQuerier) UpsertNotificationReportGeneratorLog(_ context.Context, ar
93849384
defer q.mutex.Unlock()
93859385

93869386
for i, record := range q.notificationReportGeneratorLogs {
9387-
if arg.NotificationTemplateID == record.NotificationTemplateID && arg.UserID == record.UserID {
9387+
if arg.NotificationTemplateID == record.NotificationTemplateID {
93889388
q.notificationReportGeneratorLogs[i].LastGeneratedAt = arg.LastGeneratedAt
93899389
return nil
93909390
}

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/dbmock/dbmock.go

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

coderd/database/dump.sql

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000250_email_reports.up.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ We recommend reviewing these issues to ensure future builds are successful.',
2121

2222
CREATE TABLE notification_report_generator_logs
2323
(
24-
user_id uuid NOT NULL,
2524
notification_template_id uuid NOT NULL,
2625
last_generated_at timestamp with time zone NOT NULL,
2726

28-
PRIMARY KEY (user_id, notification_template_id)
27+
PRIMARY KEY (notification_template_id)
2928
);
3029

3130
COMMENT ON TABLE notification_report_generator_logs IS 'Log of generated reports for users.';

coderd/database/models.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

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

coderd/database/queries.sql.go

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/notifications.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,20 @@ FROM notification_templates
175175
WHERE kind = @kind::notification_template_kind
176176
ORDER BY name ASC;
177177

178-
-- name: GetNotificationReportGeneratorLogByUserAndTemplate :one
178+
-- name: GetNotificationReportGeneratorLogByTemplate :one
179179
-- Fetch the notification report generator log indicating recent activity.
180180
SELECT
181181
*
182182
FROM
183183
notification_report_generator_logs
184184
WHERE
185-
user_id = $1
186-
AND notification_template_id = $2;
185+
notification_template_id = $1;
187186

188187
-- name: UpsertNotificationReportGeneratorLog :exec
189188
-- Insert or update notification report generator logs with recent activity.
190-
INSERT INTO notification_report_generator_logs (user_id, notification_template_id, last_generated_at) VALUES (@user_id, @notification_template_id, @last_generated_at)
191-
ON CONFLICT (user_id, notification_template_id) DO UPDATE set last_generated_at = EXCLUDED.last_generated_at
192-
WHERE report_generator_logs.user_id = EXCLUDED.user_id AND report_generator_logs.notification_template_id = EXCLUDED.notification_template_id;
189+
INSERT INTO notification_report_generator_logs (notification_template_id, last_generated_at) VALUES (@notification_template_id, @last_generated_at)
190+
ON CONFLICT (notification_template_id) DO UPDATE set last_generated_at = EXCLUDED.last_generated_at
191+
WHERE report_generator_logs.notification_template_id = EXCLUDED.notification_template_id;
193192

194193
-- name: DeleteOldNotificationReportGeneratorLogs :exec
195194
-- Delete report generator logs that have been created at least a @before date.

coderd/database/unique_constraint.go

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

coderd/notifications/reports/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func reportFailedWorkspaceBuilds(ctx context.Context, logger slog.Logger, db dat
137137
}
138138

139139
for _, templateAdmin := range templateAdmins {
140-
reportLog, err := db.GetNotificationReportGeneratorLogByUserAndTemplate(ctx, database.GetNotificationReportGeneratorLogByUserAndTemplateParams{
140+
reportLog, err := db.GetNotificationReportGeneratorLogByTemplate(ctx, database.GetNotificationReportGeneratorLogByTemplateParams{
141141
UserID: templateAdmin.ID,
142142
NotificationTemplateID: notifications.TemplateWorkspaceBuildsFailedReport,
143143
})

0 commit comments

Comments
 (0)