summaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-02-11 18:19:30 +0100
committerxengineering <me@xengineering.eu>2023-02-11 18:19:30 +0100
commitced1e404bd762abb114321334a3812805dee7059 (patch)
tree27f6ac74a2de4bd020af17408cd19d9e0265a501 /database.go
parent05e3b3397c888807719d70af4ed3c73397d9374f (diff)
downloadceres-ced1e404bd762abb114321334a3812805dee7059.tar
ceres-ced1e404bd762abb114321334a3812805dee7059.tar.zst
ceres-ced1e404bd762abb114321334a3812805dee7059.zip
Apply go fmt *.go
This auto-applies the recommended Go codestyle.
Diffstat (limited to 'database.go')
-rw-r--r--database.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/database.go b/database.go
index 5d9181c..6451599 100644
--- a/database.go
+++ b/database.go
@@ -1,33 +1,32 @@
-
package main
import (
- "log"
+ "database/sql"
"fmt"
- "path/filepath"
"io"
+ "log"
"os"
- "os/user"
"os/exec"
+ "os/user"
+ "path/filepath"
"strconv"
- "database/sql"
_ "github.com/go-sql-driver/mysql"
)
-const databaseSchemaVersion int = 2 // this defines the needed version for the
- // executable
+const databaseSchemaVersion int = 2 // this defines the needed version for the
+// executable
func setupDatabase() *sql.DB {
- u,err := user.Current()
+ u, err := user.Current()
if err != nil {
log.Fatal(err)
}
target := fmt.Sprintf("%s@unix(%s)/%s", u.Username, config.Database.Socket,
- config.Database.Database)
+ config.Database.Database)
- db,err := sql.Open("mysql", target)
+ db, err := sql.Open("mysql", target)
if err != nil {
log.Fatal(err)
}
@@ -46,15 +45,15 @@ func setupDatabase() *sql.DB {
func migrate(db *sql.DB) {
- const t = databaseSchemaVersion // targeted database schema version
+ const t = databaseSchemaVersion // targeted database schema version
for {
- v := schemaVersion(db) // read schema version from DB table
+ v := schemaVersion(db) // read schema version from DB table
// handle current database schema which is newer than targeted one
if v > t {
log.Fatalf(
- "Current database schema version is %d but newest is %d!", v, t)
+ "Current database schema version is %d but newest is %d!", v, t)
}
// break if targeted version is already reached
@@ -65,7 +64,7 @@ func migrate(db *sql.DB) {
// execute migration
log.Printf("Starting database schema migration to version %d.\n", v+1)
path := filepath.Join(config.Database.Migrations,
- fmt.Sprintf("%04d_migration.sql", v+1))
+ fmt.Sprintf("%04d_migration.sql", v+1))
RunSqlScript(path)
log.Printf("Finished database schema migration to version %d.\n", v+1)
}
@@ -123,7 +122,7 @@ func schemaVersion(db *sql.DB) int {
v, err := strconv.Atoi(version)
if err != nil {
log.Fatalf("Could not convert database schema version '%s' to int.\n",
- version)
+ version)
}
return v