mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 14:50:27 +00:00
Added automatic database migration.
This commit is contained in:
29
db/db.go
Normal file
29
db/db.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/emvi/logbuch"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
connectionString = `host=%s port=%s user=%s password=%s dbname=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s connectTimeout=%s timezone=%s`
|
||||
)
|
||||
|
||||
func GetConnectionString() string {
|
||||
host := os.Getenv("MB_DB_HOST")
|
||||
port := os.Getenv("MB_DB_PORT")
|
||||
user := os.Getenv("MB_DB_USER")
|
||||
password := os.Getenv("MB_DB_PASSWORD")
|
||||
schema := os.Getenv("MB_DB_SCHEMA")
|
||||
sslMode := os.Getenv("MB_DB_SSLMODE")
|
||||
sslCert := os.Getenv("MB_DB_SSLCERT")
|
||||
sslKey := os.Getenv("MB_DB_SSLKEY")
|
||||
sslRootCert := os.Getenv("MB_DB_SSLROOTCERT")
|
||||
zone, offset := time.Now().Zone()
|
||||
timezone := zone + strconv.Itoa(-offset/3600)
|
||||
logbuch.Info("Setting time zone", logbuch.Fields{"timezone": timezone})
|
||||
return fmt.Sprintf(connectionString, host, port, user, password, schema, sslMode, sslCert, sslKey, sslRootCert, "30", timezone)
|
||||
}
|
||||
Reference in New Issue
Block a user