Skip to content

Commit fe94f0d

Browse files
committed
chore(coderd/database): rework migration for legibility
1 parent 5541331 commit fe94f0d

14 files changed

+122
-87
lines changed
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
UPDATE notification_templates
22
SET
3-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text
3+
body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.suspended_account_name}}** has been suspended.'
44
WHERE
5-
id = '29a09665-2a4c-403f-9648-54301670e7be';
5+
id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d';
66

77
UPDATE notification_templates
88
SET
9-
body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.'
9+
body_template = E'Hi {{.UserName}},\nYour account **{{.Labels.suspended_account_name}}** has been suspended.'
1010
WHERE
11-
id = '9f5af851-8408-4e73-a7a1-c6502ba46689';
11+
id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff';
1212

1313
UPDATE notification_templates
1414
SET
15-
body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text
15+
body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.'
1616
WHERE
17-
id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d';
17+
id = '9f5af851-8408-4e73-a7a1-c6502ba46689';
1818

1919
UPDATE notification_templates
2020
SET
21-
body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text
21+
body_template = E'Hi {{.UserName}},\nYour account **{{.Labels.activated_account_name}}** has been activated.'
2222
WHERE
23-
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
23+
id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
2424

2525
UPDATE notification_templates
2626
SET
27-
body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n\n', E'({{.Labels.template_version_name}}).\n')::text
27+
body_template = E'Hi {{.UserName}},\n\New user account **{{.Labels.created_account_name}}** has been created.'
2828
WHERE
29-
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
29+
id = '4e19c0ac-94e1-4532-9515-d1801aa283b2';
3030

3131
UPDATE notification_templates
3232
SET
33-
body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text
33+
body_template = E'Hi {{.UserName}},\n\nUser account **{{.Labels.deleted_account_name}}** has been deleted.'
3434
WHERE
35-
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
35+
id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6';
3636

3737
UPDATE notification_templates
3838
SET
39-
body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text
39+
body_template = E'Hi {{.UserName}}\n\n' ||
40+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.'
4041
WHERE
41-
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
42+
id = '29a09665-2a4c-403f-9648-54301670e7be';
43+
44+
UPDATE notification_templates
45+
SET body_template = E'Hi {{.UserName}}\n' ||
46+
E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n' ||
47+
E'Reason for update: **{{.Labels.template_version_message}}**'
48+
WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
4249

4350
UPDATE notification_templates
4451
SET
45-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text
52+
body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
4653
WHERE
47-
id = 'f517da0b-cdc9-410f-ab89-a86107c420ed';
54+
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
4855

4956
UPDATE notification_templates
5057
SET
51-
body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text
58+
body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
5259
WHERE
5360
id = 'f517da0b-cdc9-410f-ab89-a86107c420ed';
5461

5562
UPDATE notification_templates
5663
SET
57-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text
64+
body_template = E'Hi {{.UserName}}\n\n' ||
65+
E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n' ||
66+
E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n' ||
67+
E'To prevent deletion, use your workspace with the link below.'
5868
WHERE
5969
id = '0ea69165-ec14-4314-91f1-69566ac3c5a0';
6070

6171
UPDATE notification_templates
6272
SET
63-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text
73+
body_template = E'Hi {{.UserName}}\n\n' ||
74+
E'Your workspace **{{.Labels.name}}** has been marked for **deletion** after {{.Labels.timeTilDormant}} of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of {{.Labels.reason}}.\n' ||
75+
E'To prevent deletion, use your workspace with the link below.'
6476
WHERE
6577
id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42';
6678

6779
UPDATE notification_templates
6880
SET
69-
body_template = REPLACE(body_template::text, E'\nThe workspace build was initiated by', 'The workspace build was initiated by')::text
81+
body_template = E'Hi {{.UserName}},\n\nA manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\nThe workspace build was initiated by **{{.Labels.initiator}}**.'
7082
WHERE
7183
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
72-
73-
UPDATE notification_templates
74-
SET
75-
body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text
76-
WHERE
77-
id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
78-
79-
UPDATE notification_templates
80-
SET
81-
body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text
82-
WHERE
83-
id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff';

coderd/database/migrations/000262_improve_notification_templates.up.sql

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,101 @@
11
UPDATE notification_templates
22
SET
3-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text
3+
body_template = E'Hi {{.UserName}},\n\n' ||
4+
E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' ||
5+
E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.'
46
WHERE
5-
id = '29a09665-2a4c-403f-9648-54301670e7be';
7+
id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d';
68

79
UPDATE notification_templates
810
SET
9-
body_template = E'Hi {{.UserName}},\n\n'
10-
'User account **{{.Labels.activated_account_name}}** has been activated. '
11-
'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.'
11+
body_template = E'Hi {{.UserName}},\n\n' ||
12+
E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**'
1213
WHERE
13-
id = '9f5af851-8408-4e73-a7a1-c6502ba46689';
14+
id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff';
1415

1516
UPDATE notification_templates
1617
SET
17-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text
18+
body_template = E'Hi {{.UserName}},\n\n' ||
19+
E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' ||
20+
E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.'
1821
WHERE
19-
id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d';
22+
id = '9f5af851-8408-4e73-a7a1-c6502ba46689';
2023

2124
UPDATE notification_templates
2225
SET
23-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text
26+
body_template = E'Hi {{.UserName}},\n\n' ||
27+
E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.'
2428
WHERE
25-
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
29+
id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
2630

2731
UPDATE notification_templates
2832
SET
29-
body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n', E'({{.Labels.template_version_name}}).\n\n')::text
33+
body_template = E'Hi {{.UserName}},\n\n' ||
34+
E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' ||
35+
E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**'
3036
WHERE
31-
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
37+
id = '4e19c0ac-94e1-4532-9515-d1801aa283b2';
3238

3339
UPDATE notification_templates
3440
SET
35-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text
41+
body_template = E'Hi {{.UserName}},\n\n' ||
42+
E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' ||
43+
E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.'
3644
WHERE
37-
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
45+
id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6';
3846

3947
UPDATE notification_templates
4048
SET
41-
body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text
49+
body_template = E'Hi {{.UserName}}\n\n' ||
50+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' ||
51+
E'The templates display name was **{{.Labels.display_name}}**.'
4252
WHERE
43-
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
53+
id = '29a09665-2a4c-403f-9648-54301670e7be';
54+
55+
UPDATE notification_templates
56+
SET body_template = E'Hi {{.UserName}}\n\n' ||
57+
E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n\n' ||
58+
E'Reason for update: **{{.Labels.template_version_message}}**'
59+
WHERE
60+
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
4461

4562
UPDATE notification_templates
4663
SET
47-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text
64+
body_template = E'Hi {{.UserName}}\n\n' ||
65+
E'Automatic build of your workspace **{{.Labels.name}}** failed.\n\n' ||
66+
E'The specified reason was "**{{.Labels.reason}}**".'
4867
WHERE
49-
id = 'f517da0b-cdc9-410f-ab89-a86107c420ed';
68+
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
5069

5170
UPDATE notification_templates
5271
SET
53-
body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text
72+
body_template = E'Hi {{.UserName}},\n\n' ||
73+
E'Your workspace **{{.Labels.name}}** was deleted.\n\n' ||
74+
E'The specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
5475
WHERE
5576
id = 'f517da0b-cdc9-410f-ab89-a86107c420ed';
5677

5778
UPDATE notification_templates
5879
SET
59-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text
80+
body_template = E'Hi {{.UserName}}\n\n,' || -- add comma
81+
E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n' ||
82+
E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n' ||
83+
E'To prevent deletion, use your workspace with the link below.'
6084
WHERE
6185
id = '0ea69165-ec14-4314-91f1-69566ac3c5a0';
6286

6387
UPDATE notification_templates
6488
SET
65-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text
89+
body_template = E'Hi {{.UserName}}\n\n,' || -- add comma
90+
E'Your workspace **{{.Labels.name}}** has been marked for **deletion** after {{.Labels.timeTilDormant}} of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of {{.Labels.reason}}.\n' ||
91+
E'To prevent deletion, use your workspace with the link below.'
6692
WHERE
6793
id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42';
6894

6995
UPDATE notification_templates
7096
SET
71-
body_template = REPLACE(body_template::text, 'The workspace build was initiated by', E'\nThe workspace build was initiated by')::text
97+
body_template = E'Hi {{.UserName}},\n\n' ||
98+
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
99+
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
72100
WHERE
73101
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
74-
75-
UPDATE notification_templates
76-
SET
77-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text
78-
WHERE
79-
id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
80-
81-
UPDATE notification_templates
82-
SET
83-
body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text
84-
WHERE
85-
id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff';

coderd/notifications/notifications_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,9 @@ func TestNotificationTemplates_Golden(t *testing.T) {
774774
payload: types.MessagePayload{
775775
UserName: "Bobby",
776776
Labels: map[string]string{
777-
"deleted_account_name": "bobby",
777+
"deleted_account_name": "bobby",
778+
"deleted_account_user_name": "william tables",
779+
"account_deleter_user_name": "rob",
778780
},
779781
},
780782
},
@@ -784,7 +786,9 @@ func TestNotificationTemplates_Golden(t *testing.T) {
784786
payload: types.MessagePayload{
785787
UserName: "Bobby",
786788
Labels: map[string]string{
787-
"suspended_account_name": "bobby",
789+
"suspended_account_name": "bobby",
790+
"suspended_account_user_name": "william tables",
791+
"account_suspender_user_name": "rob",
788792
},
789793
},
790794
},
@@ -794,7 +798,9 @@ func TestNotificationTemplates_Golden(t *testing.T) {
794798
payload: types.MessagePayload{
795799
UserName: "Bobby",
796800
Labels: map[string]string{
797-
"activated_account_name": "bobby",
801+
"activated_account_name": "bobby",
802+
"activated_account_user_name": "william tables",
803+
"account_activator_user_name": "rob",
798804
},
799805
},
800806
},
@@ -804,7 +810,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
804810
payload: types.MessagePayload{
805811
UserName: "Bobby",
806812
Labels: map[string]string{
807-
"suspended_account_name": "bobby",
813+
"suspended_account_name": "bobby",
814+
"account_suspender_user_name": "rob",
808815
},
809816
},
810817
},
@@ -814,7 +821,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
814821
payload: types.MessagePayload{
815822
UserName: "Bobby",
816823
Labels: map[string]string{
817-
"activated_account_name": "bobby",
824+
"activated_account_name": "bobby",
825+
"account_activator_user_name": "rob",
818826
},
819827
},
820828
},
@@ -824,8 +832,9 @@ func TestNotificationTemplates_Golden(t *testing.T) {
824832
payload: types.MessagePayload{
825833
UserName: "Bobby",
826834
Labels: map[string]string{
827-
"name": "bobby-template",
828-
"initiator": "rob",
835+
"name": "bobby-template",
836+
"display_name": "Bobby's Template",
837+
"initiator": "rob",
829838
},
830839
},
831840
},
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
Hi Bobby,
1+
Hi Bobby
22

3-
The template **bobby-template** was deleted by **rob**.
3+
The template **bobby-template** was deleted by **rob**.
4+
5+
The templates display name was **Bobby's Template**.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
User account **bobby** has been activated.
3+
User account **bobby** has been activated.
4+
5+
The newly activated account belongs to **william tables** and was activated by **rob**.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
New user account **bobby** has been created.
3+
New user account **bobby** has been created.
4+
5+
This new user account was created for **<no value>** by **<no value>**
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
User account **bobby** has been deleted.
3+
User account **bobby** has been deleted.
4+
5+
The deleted account belonged to **william tables** and was deleted by **rob**.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
User account **bobby** has been suspended.
3+
User account **bobby** has been suspended.
4+
5+
The newly suspended account belongs to **william tables** and was suspended by **rob**.

coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hi Bobby,
1+
Hi Bobby
22

33
Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).
44

coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hi Bobby,
1+
Hi Bobby
22

33
Automatic build of your workspace **bobby-workspace** failed.
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Hi Bobby,
1+
Hi Bobby
22

3-
Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.
3+
,Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.
44
Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.
55
To prevent deletion, use your workspace with the link below.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hi Bobby,
1+
Hi Bobby
22

3-
Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.
3+
,Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.
44
To prevent deletion, use your workspace with the link below.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Hi Bobby,
22

3-
Your account **bobby** has been activated.
3+
Your account **bobby** has been activated by **rob**.

0 commit comments

Comments
 (0)