Run goose migration on application startup
This commit is contained in:
parent
c6b1435875
commit
fd0a8ed972
4 changed files with 32 additions and 8 deletions
|
@ -658,15 +658,16 @@ func (h *decisionVoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
BoardMailAddress string `yaml:"board_mail_address"`
|
||||
VoteNoticeAddress string `yaml:"notice_sender_address"`
|
||||
NotificationSenderAddress string `yaml:"reminder_sender_address"`
|
||||
NoticeMailAddress string `yaml:"notice_mail_address"`
|
||||
VoteNoticeMailAddress string `yaml:"vote_notice_mail_address"`
|
||||
NotificationSenderAddress string `yaml:"notification_sender_address"`
|
||||
DatabaseFile string `yaml:"database_file"`
|
||||
ClientCACertificates string `yaml:"client_ca_certificates"`
|
||||
ServerCert string `yaml:"server_certificate"`
|
||||
ServerKey string `yaml:"server_key"`
|
||||
CookieSecret string `yaml:"cookie_secret"`
|
||||
BaseURL string `yaml:"base_url"`
|
||||
MigrationsPath string `yaml:"migrations_path"`
|
||||
MailServer struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
---
|
||||
board_mail_address: cacert-board@lists.cacert.org
|
||||
notice_sender_address: cacert-board-votes@lists.cacert.org
|
||||
reminder_sender_address: returns@cacert.org
|
||||
notice_mail_address: cacert-board@lists.cacert.org
|
||||
vote_notice_mail_address: cacert-board-votes@lists.cacert.org
|
||||
notification_sender_address: returns@cacert.org
|
||||
database_file: database.sqlite
|
||||
client_ca_certificates: cacert_class3.pem
|
||||
server_certificate: server.crt
|
||||
server_key: server.key
|
||||
cookie_secret: base64encoded_random_byte_value_of_at_least_32_bytes
|
||||
base_url: https://motions.cacert.org
|
||||
migrations_path: db
|
||||
mail_server:
|
||||
host: localhost
|
||||
port: 25
|
22
models.go
22
models.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bitbucket.org/liamstask/goose/lib/goose"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
@ -133,6 +134,27 @@ func init() {
|
|||
}
|
||||
stmt.Close()
|
||||
}
|
||||
|
||||
migrateConf := &goose.DBConf{
|
||||
MigrationsDir: config.MigrationsPath,
|
||||
Env: "production",
|
||||
Driver: goose.DBDriver{
|
||||
Name: "sqlite3",
|
||||
OpenStr: config.DatabaseFile,
|
||||
Import: "github.com/mattn/go-sqlite3",
|
||||
Dialect: &goose.Sqlite3Dialect{},
|
||||
},
|
||||
}
|
||||
|
||||
latest, err := goose.GetMostRecentDBVersion(migrateConf.MigrationsDir)
|
||||
if err != nil {
|
||||
logger.Panicln(err)
|
||||
}
|
||||
|
||||
err = goose.RunMigrationsOnDb(migrateConf, migrateConf.MigrationsDir, latest, db.DB)
|
||||
if err != nil {
|
||||
logger.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
type VoteType uint8
|
||||
|
|
|
@ -83,7 +83,7 @@ func buildMail(templateName string, context interface{}) (mailText *bytes.Buffer
|
|||
type notificationBase struct{}
|
||||
|
||||
func (n *notificationBase) getRecipient() recipientData {
|
||||
return recipientData{field: "To", address: config.BoardMailAddress, name: "CAcert board mailing list"}
|
||||
return recipientData{field: "To", address: config.NoticeMailAddress, name: "CAcert board mailing list"}
|
||||
}
|
||||
|
||||
type decisionReplyBase struct {
|
||||
|
@ -228,7 +228,7 @@ func (n *RemindVoterNotification) GetNotificationContent() *notificationContent
|
|||
type voteNotificationBase struct{}
|
||||
|
||||
func (n *voteNotificationBase) getRecipient() recipientData {
|
||||
return recipientData{"To", config.VoteNoticeAddress, "CAcert board votes mailing list"}
|
||||
return recipientData{"To", config.VoteNoticeMailAddress, "CAcert board votes mailing list"}
|
||||
}
|
||||
|
||||
type notificationProxyVote struct {
|
||||
|
|
Loading…
Reference in a new issue