v0.9.0.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package migrations
  2. import (
  3. "fmt"
  4. "github.com/jmoiron/sqlx"
  5. "github.com/knadh/koanf"
  6. "github.com/knadh/stuffbin"
  7. )
  8. // V0_9_0 performs the DB migrations for v.0.9.0.
  9. func V0_9_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
  10. if _, err := db.Exec(`
  11. INSERT INTO settings (key, value) VALUES
  12. ('app.lang', '"en"'),
  13. ('app.message_sliding_window', 'false'),
  14. ('app.message_sliding_window_duration', '"1h"'),
  15. ('app.message_sliding_window_rate', '10000'),
  16. ('app.enable_public_subscription_page', 'true')
  17. ON CONFLICT DO NOTHING;
  18. -- Add alternate (plain text) body field on campaigns.
  19. ALTER TABLE campaigns ADD COLUMN IF NOT EXISTS altbody TEXT NULL DEFAULT NULL;
  20. `); err != nil {
  21. return err
  22. }
  23. // Until this version, the default template during installation was broken!
  24. // Check if there's a broken default template and if yes, override it with the
  25. // actual one.
  26. tplBody, err := fs.Get("/static/email-templates/default.tpl")
  27. if err != nil {
  28. return fmt.Errorf("error reading default e-mail template: %v", err)
  29. }
  30. if _, err := db.Exec(`UPDATE templates SET body=$1 WHERE body=$2`,
  31. tplBody.ReadBytes(), `{{ template "content" . }}`); err != nil {
  32. return err
  33. }
  34. return nil
  35. }