summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-09 22:12:54 +0200
committerxengineering <me@xengineering.eu>2024-05-09 22:12:54 +0200
commitf7fca11c47224ff28b10a7f41fb76ce0404a0236 (patch)
treec2de6cbc562ac1cdb445039ff0f195b81a2f1607
parent228fca961ca0a2d38a61f40fee2a484e1d5190f1 (diff)
downloadceres-f7fca11c47224ff28b10a7f41fb76ce0404a0236.tar
ceres-f7fca11c47224ff28b10a7f41fb76ce0404a0236.tar.zst
ceres-f7fca11c47224ff28b10a7f41fb76ce0404a0236.zip
model: Rename version to execVersion
This makes the code easier to understand because there is an executable version and a database version handled inside that file.
-rw-r--r--model/database.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/model/database.go b/model/database.go
index b6e64bb..85d2662 100644
--- a/model/database.go
+++ b/model/database.go
@@ -78,7 +78,7 @@ func isDatabaseEmpty(tx *sql.Tx) bool {
return number == 0
}
-func setupMinimalDatabase(tx *sql.Tx, version string) error {
+func setupMinimalDatabase(tx *sql.Tx, execVersion string) error {
cmd := `
CREATE TABLE metadata (
key TEXT PRIMARY KEY,
@@ -89,7 +89,7 @@ INSERT INTO metadata
VALUES
('version', ?);
`
- _, err := tx.Exec(cmd, version)
+ _, err := tx.Exec(cmd, execVersion)
return err
}
@@ -113,11 +113,11 @@ func getDatabaseVersion(tx *sql.Tx) string {
return version
}
-func MigrateDatabase(version string) {
+func MigrateDatabase(execVersion string) {
err := Transaction(func(tx *sql.Tx) error {
if isDatabaseEmpty(tx) {
log.Println("Starting with empty database")
- err := setupMinimalDatabase(tx, version)
+ err := setupMinimalDatabase(tx, execVersion)
if err != nil {
log.Fatalf("Failed to setup minimal database schema: %v", err)
}
@@ -134,11 +134,11 @@ func MigrateDatabase(version string) {
}
dbVersion := getDatabaseVersion(tx)
- if dbVersion != version {
+ if dbVersion != execVersion {
log.Fatalf(
"Database version '%s' does not match executable version '%s'",
dbVersion,
- version,
+ execVersion,
)
}