Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-26 05:50:29 +01:00
Switch to a single config option for database connection init
The main pro is less config options, while the main con is less clarity in what the defaults are for the various database types.
Dieser Commit ist enthalten in:
Ursprung
78d07e2fda
Commit
542a73cc6e
3 geänderte Dateien mit 26 neuen und 17 gelöschten Zeilen
|
@ -31,14 +31,12 @@
|
||||||
|
|
||||||
## Database connection initialization
|
## Database connection initialization
|
||||||
## Allows SQL statements to be run whenever a new database connection is created.
|
## Allows SQL statements to be run whenever a new database connection is created.
|
||||||
## For example, this can be used to run connection-scoped pragma statements.
|
## This is mainly useful for connection-scoped pragmas.
|
||||||
##
|
## If empty, a database-specific default is used:
|
||||||
## Statements to run when creating a new SQLite connection
|
## - SQLite: "PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL;"
|
||||||
# SQLITE_CONN_INIT="PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL;"
|
## - MySQL: ""
|
||||||
## Statements to run when creating a new MySQL connection
|
## - PostgreSQL: ""
|
||||||
# MYSQL_CONN_INIT=""
|
# DATABASE_CONN_INIT=""
|
||||||
## Statements to run when creating a new PostgreSQL connection
|
|
||||||
# POSTGRESQL_CONN_INIT=""
|
|
||||||
|
|
||||||
## Individual folders, these override %DATA_FOLDER%
|
## Individual folders, these override %DATA_FOLDER%
|
||||||
# RSA_KEY_FILENAME=data/rsa_key
|
# RSA_KEY_FILENAME=data/rsa_key
|
||||||
|
|
|
@ -520,14 +520,8 @@ make_config! {
|
||||||
/// Database connection pool size
|
/// Database connection pool size
|
||||||
database_max_conns: u32, false, def, 10;
|
database_max_conns: u32, false, def, 10;
|
||||||
|
|
||||||
/// SQLite connection init |> Statements to run when creating a new SQLite connection
|
/// Database connection init |> SQL statements to run when creating a new database connection, mainly useful for connection-scoped pragmas. If empty, a database-specific default is used.
|
||||||
sqlite_conn_init: String, false, def, "PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL;".to_string();
|
database_conn_init: String, false, def, "".to_string();
|
||||||
|
|
||||||
/// MySQL connection init |> Statements to run when creating a new MySQL connection
|
|
||||||
mysql_conn_init: String, false, def, "".to_string();
|
|
||||||
|
|
||||||
/// PostgreSQL connection init |> Statements to run when creating a new PostgreSQL connection
|
|
||||||
postgresql_conn_init: String, false, def, "".to_string();
|
|
||||||
|
|
||||||
/// Bypass admin page security (Know the risks!) |> Disables the Admin Token for the admin page so you may use your own auth in-front
|
/// Bypass admin page security (Know the risks!) |> Disables the Admin Token for the admin page so you may use your own auth in-front
|
||||||
disable_admin_token: bool, true, def, false;
|
disable_admin_token: bool, true, def, false;
|
||||||
|
|
|
@ -140,7 +140,7 @@ macro_rules! generate_connections {
|
||||||
.max_size(CONFIG.database_max_conns())
|
.max_size(CONFIG.database_max_conns())
|
||||||
.connection_timeout(Duration::from_secs(CONFIG.database_timeout()))
|
.connection_timeout(Duration::from_secs(CONFIG.database_timeout()))
|
||||||
.connection_customizer(Box::new(DbConnOptions{
|
.connection_customizer(Box::new(DbConnOptions{
|
||||||
init_stmts: paste::paste!{ CONFIG. [< $name _conn_init >] () }
|
init_stmts: conn_type.get_init_stmts()
|
||||||
}))
|
}))
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.map_res("Failed to create pool")?;
|
.map_res("Failed to create pool")?;
|
||||||
|
@ -215,6 +215,23 @@ impl DbConnType {
|
||||||
err!("`DATABASE_URL` looks like a SQLite URL, but 'sqlite' feature is not enabled")
|
err!("`DATABASE_URL` looks like a SQLite URL, but 'sqlite' feature is not enabled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_init_stmts(&self) -> String {
|
||||||
|
let init_stmts = CONFIG.database_conn_init();
|
||||||
|
if !init_stmts.is_empty() {
|
||||||
|
init_stmts
|
||||||
|
} else {
|
||||||
|
self.default_init_stmts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_init_stmts(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::sqlite => "PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL;".to_string(),
|
||||||
|
Self::mysql => "".to_string(),
|
||||||
|
Self::postgresql => "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
Laden …
In neuem Issue referenzieren