Skip to content

Commit 05928d5

Browse files
committed
Fix default campaign template not being setup on first install.
This was a ridiculous miss, where on first time installation, the well designed default e-mail template was never installed in the DB! I never spotted this because my local dev setup, and surprisingly, nobody ever complained that the default campaign template was a blank slate with no styles.
1 parent 0add1c4 commit 05928d5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

cmd/install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ func install(lastVer string, db *sqlx.DB, fs stuffbin.FileSystem, prompt bool) {
9696
}
9797

9898
// Default template.
99-
tplBody, err := ioutil.ReadFile("static/email-templates/default.tpl")
99+
tplBody, err := fs.Get("/static/email-templates/default.tpl")
100100
if err != nil {
101-
tplBody = []byte(tplTag)
101+
lo.Fatalf("error reading default e-mail template: %v", err)
102102
}
103103

104104
var tplID int
105105
if err := q.CreateTemplate.Get(&tplID,
106106
"Default template",
107-
string(tplBody),
107+
string(tplBody.ReadBytes()),
108108
); err != nil {
109109
lo.Fatalf("error creating default template: %v", err)
110110
}

internal/migrations/v0.9.0.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
package migrations
22

33
import (
4+
"fmt"
5+
46
"github.com/jmoiron/sqlx"
57
"github.com/knadh/koanf"
68
"github.com/knadh/stuffbin"
79
)
810

911
// V0_9_0 performs the DB migrations for v.0.9.0.
1012
func V0_9_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
11-
_, err := db.Exec(`
13+
if _, err := db.Exec(`
1214
INSERT INTO settings (key, value) VALUES
1315
('app.lang', '"en"'),
1416
('app.message_sliding_window', 'false'),
1517
('app.message_sliding_window_duration', '"1h"'),
1618
('app.message_sliding_window_rate', '10000')
1719
ON CONFLICT DO NOTHING;
18-
`)
19-
return err
20+
`); err != nil {
21+
return err
22+
}
23+
24+
// Until this version, the default template during installation was broken!
25+
// Check if there's a broken default template and if yes, override it with the
26+
// actual one.
27+
tplBody, err := fs.Get("/static/email-templates/default.tpl")
28+
if err != nil {
29+
return fmt.Errorf("error reading default e-mail template: %v", err)
30+
}
31+
32+
if _, err := db.Exec(`UPDATE templates SET body=$1 WHERE body=$2`,
33+
tplBody.ReadBytes(), `{{ template "content" . }}`); err != nil {
34+
return err
35+
}
36+
return nil
2037
}

0 commit comments

Comments
 (0)