Skip to content

chore: explore possibility of switching to file-based notification templates #17302

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

Open
DanielleMaywood opened this issue Apr 9, 2025 · 1 comment

Comments

@DanielleMaywood
Copy link
Contributor

Problem

Currently we store our notification templates in the database.

If we want to make small changes to our notifications we have to make migrations like the following:

Whilst this isn't difficult to do, it does feel a bit janky.

Proposed solution

We move to file-based notification templates. These could be embedded in the Go binary with the embed package.

An example

Given the following notification template:

INSERT INTO notification_templates
	(id, name, title_template, body_template, "group", actions)
VALUES (
	'a9d027b4-ac49-4fb1-9f6d-45af15f64e7a',
	'Workspace Out Of Memory',
	E'Your workspace "{{.Labels.workspace}}" is low on memory',
	E'Hi {{.UserName}},\n\n'||
		E'Your workspace **{{.Labels.workspace}}** has reached the memory usage threshold set at **{{.Labels.threshold}}**.',
	'Workspace Events',
	'[
		{
			"label": "View workspace",
			"url": "{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}"
		}
	]'::jsonb
);

We could store this in a TOML file with the design:

id    = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
name  = "Workspace Out Of Memory"
group = "Workspace Events"

title_template = 'Your workspace "{{.Labels.workspace}}" is low on memory'
body_template = '''
Hi {{.UserName}},

Your workspace **{{.Labels.workspace}}** has reached the memory usage threshold set at **{{.Labels.threshold}}*.
'''

[[actions]]
label = "View workspace"
url   = '{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}'

Any future changes to this notification wouldn't require creating a new migration where you need to ensure the down migration goes back to the correct state.

Custom Notifications

The original database oriented design was indented to allow making it easy for supporting the use-case of custom notifications. This solution could support that by having a table in the database that stores custom notifications templates.

@dannykopping
Copy link
Contributor

Thanks for this 👍

We'd need some common interface in front of whatever retrieves these templates to fetch either from memory (embedding) or from the DB by ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants