11use serde:: { Deserialize , Serialize } ;
2- use torrust_tracker_primitives:: DatabaseDriver ;
32use url:: Url ;
43
54#[ allow( clippy:: struct_excessive_bools) ]
@@ -8,7 +7,7 @@ pub struct Database {
87 // Database configuration
98 /// Database driver. Possible values are: `Sqlite3`, and `MySQL`.
109 #[ serde( default = "Database::default_driver" ) ]
11- pub driver : DatabaseDriver ,
10+ pub driver : Driver ,
1211
1312 /// Database connection string. The format depends on the database driver.
1413 /// For `Sqlite3`, the format is `path/to/database.db`, for example:
@@ -29,8 +28,8 @@ impl Default for Database {
2928}
3029
3130impl Database {
32- fn default_driver ( ) -> DatabaseDriver {
33- DatabaseDriver :: Sqlite3
31+ fn default_driver ( ) -> Driver {
32+ Driver :: Sqlite3
3433 }
3534
3635 fn default_path ( ) -> String {
@@ -44,10 +43,10 @@ impl Database {
4443 /// Will panic if the database path for `MySQL` is not a valid URL.
4544 pub fn mask_secrets ( & mut self ) {
4645 match self . driver {
47- DatabaseDriver :: Sqlite3 => {
46+ Driver :: Sqlite3 => {
4847 // Nothing to mask
4948 }
50- DatabaseDriver :: MySQL => {
49+ Driver :: MySQL => {
5150 let mut url = Url :: parse ( & self . path ) . expect ( "path for MySQL driver should be a valid URL" ) ;
5251 url. set_password ( Some ( "***" ) ) . expect ( "url password should be changed" ) ;
5352 self . path = url. to_string ( ) ;
@@ -56,17 +55,27 @@ impl Database {
5655 }
5756}
5857
58+ /// The database management system used by the tracker.
59+ #[ derive( Serialize , Deserialize , PartialEq , Eq , PartialOrd , Ord , Debug , Hash , Clone ) ]
60+ pub enum Driver {
61+ // todo:
62+ // - Rename serialized values to lowercase: `sqlite3` and `mysql`.
63+ // - Add serde default values.
64+ /// The `Sqlite3` database driver.
65+ Sqlite3 ,
66+ /// The `MySQL` database driver.
67+ MySQL ,
68+ }
69+
5970#[ cfg( test) ]
6071mod tests {
6172
62- use torrust_tracker_primitives:: DatabaseDriver ;
63-
64- use super :: Database ;
73+ use super :: { Database , Driver } ;
6574
6675 #[ test]
6776 fn it_should_allow_masking_the_mysql_user_password ( ) {
6877 let mut database = Database {
69- driver : DatabaseDriver :: MySQL ,
78+ driver : Driver :: MySQL ,
7079 path : "mysql://root:password@localhost:3306/torrust" . to_string ( ) ,
7180 } ;
7281
0 commit comments