Skip to content

feat: create database tables and queries for notifications #13536

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 5 commits into from
Jun 28, 2024

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Jun 11, 2024

Creates two new tables:

  • notification_templates: templates are used to create notifications from, and specify a unique event in the system
    • right now this will just store immutable system notification templates, but in the future users will be able to configure their own notification templates (e.g. notify when a workspace's disk is 90% full)
  • notification_messages: each record corresponds to a separate notification which must be delivered to a user
    • this table is effectively a queue, and queue consumers can consume these records concurrently with safety (see AcquireNotificationMessages)

coderd/database/migrations/000219_notifications.up.sql inserts a single template ("Workspace Deleted"), for which we are creating this vertical slice in this initial stack of PRs.

Copy link
Contributor Author

dannykopping commented Jun 11, 2024

@dannykopping dannykopping force-pushed the dk/system-notifications-database branch from 1cb776a to 25636ec Compare June 11, 2024 13:15
@dannykopping dannykopping changed the title feat: database tables & queries feat: create database tables and queries for notifications Jun 11, 2024
@dannykopping dannykopping marked this pull request as ready for review June 11, 2024 14:13
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments below, but nothing blocking.

@dannykopping dannykopping force-pushed the dk/system-notifications-database branch from 1c4046c to 538bc42 Compare June 12, 2024 09:08
@dannykopping dannykopping force-pushed the dk/system-notifications-database branch from 538bc42 to 438bcba Compare June 12, 2024 10:51
@github-actions github-actions bot added the stale This issue is like stale bread. label Jun 20, 2024
@github-actions github-actions bot closed this Jun 23, 2024
@johnstcn johnstcn reopened this Jun 23, 2024
@johnstcn johnstcn removed the stale This issue is like stale bread. label Jun 23, 2024
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
This has the unfortunate side-effect of not allowing the AcquireNotificationMessagesRow.Payload type to be overriden to []byte as it was previously, but it does not change the semantics

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping force-pushed the dk/system-notifications-database branch from 438bcba to c1a3010 Compare June 27, 2024 09:46
Copy link
Contributor Author

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spikecurtis I'm back from PTO. I believe I've addressed all of your comments.
Can you please have another look?

Copy link
Contributor

@spikecurtis spikecurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

One comment inline, but I don't need to review again.

WHEN (attempt_count + 1 < @max_attempts::int)
THEN NOW() + CONCAT(@retry_interval::int, ' seconds')::interval END
FROM (SELECT id, status, status_reason, failed_at
FROM new_values) AS subquery
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query is also doing the WITH new_values thing where we then essentially rename new_values to subquery. Can be simplified to remove the WITH clause and unnest the values here in the FROM clause.

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping enabled auto-merge (squash) June 28, 2024 09:14
@dannykopping dannykopping merged commit 0a221e8 into main Jun 28, 2024
28 checks passed
@dannykopping dannykopping deleted the dk/system-notifications-database branch June 28, 2024 09:21
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants