diff --git a/README.md b/README.md index b83b4d9..f67d0ac 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,17 @@ You can specify configuration options either via a config file (default: `config | `db.user` | `WAKAPI_DB_USER` | - | Database user | | `db.password` | `WAKAPI_DB_PASSWORD` | - | Database password | | `db.name` | `WAKAPI_DB_NAME` | `wakapi_db.db` | Database name | -| `db.dialect` | `WAKAPI_DB_TYPE` | `sqlite3` | Database type (one of sqlite3, mysql, postgres) | +| `db.dialect` | `WAKAPI_DB_TYPE` | `sqlite3` | Database type (one of `sqlite3`, `mysql`, `postgres`, `cockroach`) | | `db.max_conn` | `WAKAPI_DB_MAX_CONNECTIONS` | `2` | Maximum number of database connections | +| `db.ssl` | `WAKAPI_DB_SSL` | `false` | Whether to use TLS encryption for database connection (Postgres and CockroachDB only) | + +### Supported databases +Wakapi uses [GORM](https://gorm.io) as an ORM. As a consequence, a set of different relational databases is supported. +* [SQLite](https://sqlite.org/) (_default, easy setup_) +* [MySQL](https://hub.docker.com/_/mysql) (_recommended, because most extensively tested_) +* [MariaDB](https://hub.docker.com/_/mariadb) (_open-source MySQL alternative_) +* [Postgres](https://hub.docker.com/_/postgres) (_open-source as well_) +* [CockroachDB](https://www.cockroachlabs.com/docs/stable/install-cockroachdb-linux.html) (_cloud-native, distributed, Postgres-compatible API_) ## 💻 Client Setup Wakapi relies on the open-source [WakaTime](https://github.com/wakatime/wakatime) client tools. In order to collect statistics to Wakapi, you need to set them up. diff --git a/config.default.yml b/config.default.yml index e21a61c..78b61a0 100644 --- a/config.default.yml +++ b/config.default.yml @@ -22,7 +22,8 @@ db: password: # leave blank when using sqlite3 name: wakapi_db.db # database name for mysql / postgres or file path for sqlite (e.g. /tmp/wakapi.db) dialect: sqlite3 # mysql, postgres, sqlite3 - max_conn: 2 + max_conn: 2 # maximum number of concurrent connections to maintain + ssl: false # whether to use tls for db connection (must be true for cockroachdb) (ignored for mysql and sqlite) security: password_salt: # CHANGE ! diff --git a/config/config.go b/config/config.go index 1240c9b..a24047f 100644 --- a/config/config.go +++ b/config/config.go @@ -56,8 +56,10 @@ type dbConfig struct { User string `env:"WAKAPI_DB_USER"` Password string `env:"WAKAPI_DB_PASSWORD"` Name string `default:"wakapi_db.db" env:"WAKAPI_DB_NAME"` - Dialect string `default:"sqlite3" env:"WAKAPI_DB_TYPE"` + Dialect string `yaml:"-"` + Type string `yaml:"dialect" default:"sqlite3" env:"WAKAPI_DB_TYPE"` MaxConn uint `yaml:"max_conn" default:"2" env:"WAKAPI_DB_MAX_CONNECTIONS"` + Ssl bool `default:"false" env:"WAKAPI_DB_SSL"` } type serverConfig struct { @@ -170,12 +172,18 @@ func mysqlConnectionString(config *dbConfig) string { } func postgresConnectionString(config *dbConfig) string { - return fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=disable", + sslmode := "disable" + if config.Ssl { + sslmode = "require" + } + + return fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=%s", config.Host, config.Port, config.User, config.Name, config.Password, + sslmode, ) } @@ -243,6 +251,13 @@ func mustReadConfigLocation() string { return *cFlag } +func resolveDbDialect(dbType string) string { + if dbType == "cockroach" { + return "postgres" + } + return dbType +} + func Set(config *Config) { cfg = config } @@ -264,6 +279,7 @@ func Load() *Config { config.Version = readVersion() config.App.LanguageColors = readLanguageColors() + config.Db.Dialect = resolveDbDialect(config.Db.Type) config.Security.SecureCookie = securecookie.New( securecookie.GenerateRandomKey(64), securecookie.GenerateRandomKey(32), diff --git a/routes/routes.go b/routes/routes.go index 70b8e28..576a995 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -31,7 +31,7 @@ func loadTemplates() { return config.Get().Version }, "getDbType": func() string { - return strings.ToLower(config.Get().Db.Dialect) + return strings.ToLower(config.Get().Db.Type) }, "htmlSafe": func(html string) template.HTML { return template.HTML(html) diff --git a/version.txt b/version.txt index b57fc72..b9fb27a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.18.2 +1.18.3