Skip to content

Commit

Permalink
feat: Put MySQL and Sqlite test connexions behind flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Eragonfr committed Nov 20, 2024
1 parent f2f12fa commit 8eb5041
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions syncserver-db-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ syncserver-common = { path = "../syncserver-common" }

[features]
sql = []
mysql = ["sql"]
sqlite = ["sql"]
9 changes: 7 additions & 2 deletions syncserver-db-common/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use diesel::{
mysql::MysqlConnection,
r2d2::{CustomizeConnection, Error as PoolError},
sqlite::SqliteConnection,
Connection,
};

#[cfg(feature = "mysql")]
use diesel::mysql::MysqlConnection;
#[cfg(feature = "sqlite")]
use diesel::sqlite::SqliteConnection;

#[derive(Debug)]
pub struct TestTransactionCustomizer;

#[cfg(feature = "mysql")]
impl CustomizeConnection<MysqlConnection, PoolError> for TestTransactionCustomizer {
fn on_acquire(&self, conn: &mut MysqlConnection) -> Result<(), PoolError> {
conn.begin_test_transaction().map_err(PoolError::QueryError)
}
}

#[cfg(feature = "sqlite")]
impl CustomizeConnection<SqliteConnection, PoolError> for TestTransactionCustomizer {
fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), PoolError> {
conn.begin_test_transaction().map_err(PoolError::QueryError)
Expand Down
2 changes: 1 addition & 1 deletion syncstorage-mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ diesel = { workspace = true, features = ["mysql", "r2d2"] }
diesel_logger = { workspace = true }
diesel_migrations = { workspace = true, features = ["mysql"] }
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common", features = ["sql"] }
syncserver-db-common = { path = "../syncserver-db-common", features = ["mysql"] }
syncstorage-db-common = { path = "../syncstorage-db-common" }
syncstorage-settings = { path = "../syncstorage-settings" }
syncstorage-sql-db-common = { path = "../syncstorage-sql-db-common" }
Expand Down
10 changes: 5 additions & 5 deletions syncstorage-sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ base64.workspace=true
futures.workspace=true
http.workspace=true
slog-scope.workspace=true
thiserror.workspace = true
diesel_logger.workspace = true

async-trait = "0.1.40"
diesel = { version = "1.4", features = ["sqlite", "r2d2"] }
diesel_logger = "0.1.1"
diesel_migrations = { version = "1.4.0", features = ["sqlite"] }
diesel = { workspace = true, features = ["sqlite", "r2d2"] }
diesel_migrations = { workspace = true, features = ["sqlite"] }
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common", features = ["sql"] }
syncserver-db-common = { path = "../syncserver-db-common", features = ["sqlite"] }
syncstorage-db-common = { path = "../syncstorage-db-common" }
syncstorage-settings = { path = "../syncstorage-settings" }
syncstorage-sql-db-common = { path = "../syncstorage-sql-db-common" }
thiserror = "1.0.26"
url = "2.1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tokenserver-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ diesel = { workspace = true, features = ["mysql", "r2d2"] }
diesel_logger = { workspace = true }
diesel_migrations = { workspace = true, features = ["mysql"] }
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common", features = ["sql"] }
syncserver-db-common = { path = "../syncserver-db-common", features = ["mysql", "sqlite"] }
tokenserver-common = { path = "../tokenserver-common" }
tokenserver-settings = { path = "../tokenserver-settings" }
tokenserver-db-common = { path = "../tokenserver-db-common" }
Expand Down

0 comments on commit 8eb5041

Please sign in to comment.