Skip to content

Commit 9d72f51

Browse files
committed
feat: [#950] use lowercase for database driver values in configuration
```toml [core.database] driver = "sqlite3" ``` We are normalizing all enum variants in configration to lowercase.
1 parent d970bb8 commit 9d72f51

File tree

9 files changed

+15
-17
lines changed

9 files changed

+15
-17
lines changed

Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ RUN ["/busybox/cp", "-sp", "/busybox/sh","/busybox/cat","/busybox/ls","/busybox/
9696
COPY --from=gcc --chmod=0555 /usr/local/bin/su-exec /bin/su-exec
9797

9898
ARG TORRUST_TRACKER_CONFIG_TOML_PATH="/etc/torrust/tracker/tracker.toml"
99-
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER="Sqlite3"
99+
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER="sqlite3"
100100
ARG USER_ID=1000
101101
ARG UDP_PORT=6969
102102
ARG HTTP_PORT=7070

compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
image: torrust-tracker:release
55
tty: true
66
environment:
7-
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-MySQL}
7+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-mysql}
88
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
99
networks:
1010
- server_side

docs/containers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ The following environmental variables can be set:
149149

150150
- `TORRUST_TRACKER_CONFIG_TOML_PATH` - The in-container path to the tracker configuration file, (default: `"/etc/torrust/tracker/tracker.toml"`).
151151
- `TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN` - Override of the admin token. If set, this value overrides any value set in the config.
152-
- `TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER` - The database type used for the container, (options: `Sqlite3`, `MySQL`, default `Sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
152+
- `TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER` - The database type used for the container, (options: `sqlite3`, `mysql`, default `sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
153153
- `TORRUST_TRACKER_CONFIG_TOML` - Load config from this environmental variable instead from a file, (i.e: `TORRUST_TRACKER_CONFIG_TOML=$(cat tracker-tracker.toml)`).
154154
- `USER_ID` - The user id for the runtime crated `torrust` user. Please Note: This user id should match the ownership of the host-mapped volumes, (default `1000`).
155155
- `UDP_PORT` - The port for the UDP tracker. This should match the port used in the configuration, (default `6969`).
@@ -244,7 +244,7 @@ The docker-compose configuration includes the MySQL service configuration. If yo
244244

245245
```toml
246246
[core.database]
247-
driver = "MySQL"
247+
driver = "mysql"
248248
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
249249
```
250250

packages/configuration/src/v2/database.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use url::Url;
55
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
66
pub struct Database {
77
// Database configuration
8-
/// Database driver. Possible values are: `Sqlite3`, and `MySQL`.
8+
/// Database driver. Possible values are: `sqlite3`, and `mysql`.
99
#[serde(default = "Database::default_driver")]
1010
pub driver: Driver,
1111

1212
/// Database connection string. The format depends on the database driver.
13-
/// For `Sqlite3`, the format is `path/to/database.db`, for example:
13+
/// For `sqlite3`, the format is `path/to/database.db`, for example:
1414
/// `./storage/tracker/lib/database/sqlite3.db`.
1515
/// For `Mysql`, the format is `mysql://db_user:db_user_password:port/db_name`, for
1616
/// example: `mysql://root:password@localhost:3306/torrust`.
@@ -57,10 +57,8 @@ impl Database {
5757

5858
/// The database management system used by the tracker.
5959
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
60+
#[serde(rename_all = "lowercase")]
6061
pub enum Driver {
61-
// todo:
62-
// - Rename serialized values to lowercase: `sqlite3` and `mysql`.
63-
// - Add serde default values.
6462
/// The `Sqlite3` database driver.
6563
Sqlite3,
6664
/// The `MySQL` database driver.

packages/configuration/src/v2/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
//! interval_min = 120
210210
//!
211211
//! [core.database]
212-
//! driver = "Sqlite3"
212+
//! driver = "sqlite3"
213213
//! path = "./storage/tracker/lib/database/sqlite3.db"
214214
//!
215215
//! [core.net]
@@ -420,7 +420,7 @@ mod tests {
420420
interval_min = 120
421421
422422
[core.database]
423-
driver = "Sqlite3"
423+
driver = "sqlite3"
424424
path = "./storage/tracker/lib/database/sqlite3.db"
425425
426426
[core.net]

share/container/entry_script_sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ chmod -R 2770 /var/lib/torrust /var/log/torrust /etc/torrust
2727

2828
# Install the database and config:
2929
if [ -n "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" ]; then
30-
if cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "Sqlite3"; then
30+
if cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "sqlite3"; then
3131

3232
# Select Sqlite3 empty database
3333
default_database="/usr/share/torrust/default/database/tracker.sqlite3.db"
3434

3535
# Select Sqlite3 default configuration
3636
default_config="/usr/share/torrust/default/config/tracker.container.sqlite3.toml"
3737

38-
elif cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "MySQL"; then
38+
elif cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "mysql"; then
3939

4040
# (no database file needed for MySQL)
4141

@@ -44,7 +44,7 @@ if [ -n "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" ]; then
4444

4545
else
4646
echo "Error: Unsupported Database Type: \"$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER\"."
47-
echo "Please Note: Supported Database Types: \"Sqlite3\", \"MySQL\"."
47+
echo "Please Note: Supported Database Types: \"sqlite3\", \"mysql\"."
4848
exit 1
4949
fi
5050
else

share/default/config/tracker.container.mysql.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version = "2"
22

33
[core.database]
4-
driver = "MySQL"
4+
driver = "mysql"
55
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
66

77
# Uncomment to enable services

src/core/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
//! interval_min = 120
327327
//!
328328
//! [core.database]
329-
//! driver = "Sqlite3"
329+
//! driver = "sqlite3"
330330
//! path = "./storage/tracker/lib/database/sqlite3.db"
331331
//!
332332
//! [core.net]

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
//! interval_min = 120
182182
//!
183183
//! [core.database]
184-
//! driver = "Sqlite3"
184+
//! driver = "sqlite3"
185185
//! path = "./storage/tracker/lib/database/sqlite3.db"
186186
//!
187187
//! [core.net]

0 commit comments

Comments
 (0)