summaryrefslogtreecommitdiff
path: root/persistence
diff options
context:
space:
mode:
Diffstat (limited to 'persistence')
-rw-r--r--persistence/sqlite/sqliteRepository.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/persistence/sqlite/sqliteRepository.go b/persistence/sqlite/sqliteRepository.go
index dfeb23a..9e0e3f5 100644
--- a/persistence/sqlite/sqliteRepository.go
+++ b/persistence/sqlite/sqliteRepository.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"log"
+ "os"
_ "modernc.org/sqlite"
@@ -92,3 +93,28 @@ func (repo *sqliteRepository) checkInit() (*sql.DB, error) {
}
return db, nil
}
+
+func (repo *sqliteRepository) Migrate() error {
+ db, err := repo.checkInit()
+ if err != nil {
+ return err
+ }
+ var schema_version int64
+ err = db.QueryRow("PRAGMA user_version").Scan(&schema_version)
+
+ if err != nil {
+ return err
+ }
+ // Initial / fresh table
+ if schema_version == 0 {
+ var sql []byte
+ sql, err = os.ReadFile("./0001_Create_Initial_Tables.sql")
+ if err != nil {
+ return err
+ }
+ sqlString := string(sql)
+ _, err = db.Exec(sqlString)
+ }
+
+ return err
+}