summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--model/database.go21
-rw-r--r--model/migrations/migration001.go15
-rw-r--r--model/migrations/migration001.sql (renamed from model/sql/migrate.sql)0
3 files changed, 18 insertions, 18 deletions
diff --git a/model/database.go b/model/database.go
index f5fd67a..4740899 100644
--- a/model/database.go
+++ b/model/database.go
@@ -2,26 +2,15 @@ package model
import (
"database/sql"
- "embed"
"log"
_ "github.com/mattn/go-sqlite3"
+
+ "xengineering.eu/ceres/model/migrations"
)
var db *sql.DB
-//go:embed sql/*.sql
-var sqlCode embed.FS
-
-func GetSql(code string) (string, error) {
- query, err := sqlCode.ReadFile("sql/" + code + ".sql")
- if err != nil {
- return "", err
- }
-
- return string(query), nil
-}
-
func ConnectDatabase(path string) {
var err error
@@ -123,11 +112,7 @@ func MigrateDatabase(execVersion string) {
}
log.Println("Executing initial migration")
- query, err := GetSql(`migrate`)
- if err != nil {
- log.Fatal(err)
- }
- _, err = tx.Exec(query)
+ err = migrations.Migration001(tx)
if err != nil {
return err
}
diff --git a/model/migrations/migration001.go b/model/migrations/migration001.go
new file mode 100644
index 0000000..11f062f
--- /dev/null
+++ b/model/migrations/migration001.go
@@ -0,0 +1,15 @@
+package migrations
+
+import (
+ "database/sql"
+ _ "embed"
+)
+
+//go:embed migration001.sql
+var migration001sql string
+
+func Migration001(tx *sql.Tx) error {
+ _, err := tx.Exec(migration001sql)
+
+ return err
+}
diff --git a/model/sql/migrate.sql b/model/migrations/migration001.sql
index 46f9fc6..46f9fc6 100644
--- a/model/sql/migrate.sql
+++ b/model/migrations/migration001.sql