summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/database.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/model/database.go b/model/database.go
index 16a6cea..cdded4a 100644
--- a/model/database.go
+++ b/model/database.go
@@ -78,10 +78,29 @@ func isDatabaseEmpty(tx *sql.Tx) bool {
return number == 0
}
-func MigrateDatabase() {
+func setupMinimalDatabase(tx *sql.Tx, version string) error {
+ cmd := `
+CREATE TABLE metadata (
+ key TEXT PRIMARY KEY,
+ value TEXT
+);
+INSERT INTO metadata
+ (key, value)
+VALUES
+ ('version', ?);
+`
+ _, err := tx.Exec(cmd, version)
+ return err
+}
+
+func MigrateDatabase(version string) {
err := Transaction(func(tx *sql.Tx) error {
if isDatabaseEmpty(tx) {
log.Println("Starting with empty database")
+ err := setupMinimalDatabase(tx, version)
+ if err != nil {
+ log.Fatalf("Failed to setup minimal database schema: %v", err)
+ }
}
query, err := GetSql(`migrate`)