summaryrefslogtreecommitdiff
path: root/models.go
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2017-04-21 21:41:25 +0200
committerJan Dittberner <jan@dittberner.info>2017-04-22 00:14:38 +0200
commitfd0a8ed972f6b9327d118292b46ab5c601a48ac3 (patch)
tree867268f77f669e7e92b6d1fad3781d1901f05cd7 /models.go
parentc6b1435875594ad568116da1c6ef1b27cb2f2ffe (diff)
downloadcacert-boardvoting-fd0a8ed972f6b9327d118292b46ab5c601a48ac3.tar.gz
cacert-boardvoting-fd0a8ed972f6b9327d118292b46ab5c601a48ac3.tar.xz
cacert-boardvoting-fd0a8ed972f6b9327d118292b46ab5c601a48ac3.zip
Run goose migration on application startup
Diffstat (limited to 'models.go')
-rw-r--r--models.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/models.go b/models.go
index d124387..f6dc884 100644
--- a/models.go
+++ b/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