v0.9.0.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. ON CONFLICT DO NOTHING;
  17. `); err != nil {
  18. return err
  19. }
  20. // Until this version, the default template during installation was broken!
  21. // Check if there's a broken default template and if yes, override it with the
  22. // actual one.
  23. tplBody, err := fs.Get("/static/email-templates/default.tpl")
  24. if err != nil {
  25. return fmt.Errorf("error reading default e-mail template: %v", err)
  26. }
  27. if _, err := db.Exec(`UPDATE templates SET body=$1 WHERE body=$2`,
  28. tplBody.ReadBytes(), `{{ template "content" . }}`); err != nil {
  29. return err
  30. }
  31. return nil
  32. }