diff --git a/eden/mononoke/commit_cloud/src/sql/builder.rs b/eden/mononoke/commit_cloud/src/sql/builder.rs index 1c46542b28..8daca9f418 100644 --- a/eden/mononoke/commit_cloud/src/sql/builder.rs +++ b/eden/mononoke/commit_cloud/src/sql/builder.rs @@ -37,7 +37,7 @@ impl SqlConstructFromMetadataDatabaseConfig for SqlCommitCloudBuilder { } impl SqlCommitCloudBuilder { - pub fn new(self) -> SqlCommitCloud { - SqlCommitCloud::new(self.connections) + pub fn new(self, uses_mysql: bool) -> SqlCommitCloud { + SqlCommitCloud::new(self.connections, uses_mysql) } } diff --git a/eden/mononoke/commit_cloud/src/sql/ops.rs b/eden/mononoke/commit_cloud/src/sql/ops.rs index 655a8d5735..6b057052b2 100644 --- a/eden/mononoke/commit_cloud/src/sql/ops.rs +++ b/eden/mononoke/commit_cloud/src/sql/ops.rs @@ -11,11 +11,21 @@ use sql_ext::SqlConnections; pub struct SqlCommitCloud { #[allow(unused)] pub(crate) connections: SqlConnections, + // Commit cloud has three databases in mononoke: + // 1. xdb.commit_cloud (prod) This is a mysql db used in prod + // 2. sqlite db (test) This is created from sqlite-commit-cloud.sql. Used for unit tests. + // 3. mock mysql db (test) This is used in integration tests, it's never queried or populated, + /// just there to avoid a clash between "bookmarks" tables + #[allow(unused)] + uses_mysql: bool, } impl SqlCommitCloud { - pub fn new(connections: SqlConnections) -> Self { - Self { connections } + pub fn new(connections: SqlConnections, uses_mysql: bool) -> Self { + Self { + connections, + uses_mysql, + } } } diff --git a/eden/mononoke/commit_cloud/tests/main.rs b/eden/mononoke/commit_cloud/tests/main.rs index 54947fadf5..89796333c8 100644 --- a/eden/mononoke/commit_cloud/tests/main.rs +++ b/eden/mononoke/commit_cloud/tests/main.rs @@ -25,7 +25,7 @@ use sql_construct::SqlConstruct; #[fbinit::test] async fn test_checkout_locations(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::ops::Get; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -53,7 +53,7 @@ async fn test_snapshots(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::ops::Get; use commit_cloud::sql::snapshots::DeleteArgs; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -94,7 +94,7 @@ async fn test_snapshots(_fb: FacebookInit) -> anyhow::Result<()> { async fn test_heads(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::heads::DeleteArgs; use commit_cloud::sql::ops::Get; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -135,7 +135,7 @@ async fn test_local_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::local_bookmarks::DeleteArgs; use commit_cloud::sql::ops::Get; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -177,7 +177,7 @@ async fn test_local_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> { async fn test_remote_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::ops::Get; use commit_cloud::sql::remote_bookmarks::DeleteArgs; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -223,7 +223,7 @@ async fn test_remote_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> { #[fbinit::test] async fn test_versions(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::ops::Get; - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); @@ -252,7 +252,7 @@ async fn test_history(_fb: FacebookInit) -> anyhow::Result<()> { use commit_cloud::sql::ops::GenericGet; // Create a workspace with heads and bookmarks - let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(); + let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false); let reponame = "test_repo".to_owned(); let workspace = "user_testuser_default".to_owned(); let timestamp = Timestamp::now(); diff --git a/eden/mononoke/repo_factory/src/lib.rs b/eden/mononoke/repo_factory/src/lib.rs index dc482bd587..cdf965632c 100644 --- a/eden/mononoke/repo_factory/src/lib.rs +++ b/eden/mononoke/repo_factory/src/lib.rs @@ -1713,7 +1713,10 @@ impl RepoFactory { .await .context(RepoFactoryError::SqlCommitCloud)?; Ok(Arc::new(CommitCloud { - storage: sql_commit_cloud.new(), + storage: sql_commit_cloud.new(matches!( + &repo_config.storage_config.metadata, + MetadataDatabaseConfig::Remote(_) + )), })) } } diff --git a/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs b/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs index 598a4608dc..9815712ada 100644 --- a/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs +++ b/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs @@ -870,7 +870,8 @@ impl TestRepoFactory { /// Commit cloud pub fn commit_cloud(&self, _repo_identity: &RepoIdentity) -> Result { Ok(Arc::new(commit_cloud::CommitCloud { - storage: SqlCommitCloudBuilder::from_sql_connections(self.metadata_db.clone()).new(), + storage: SqlCommitCloudBuilder::from_sql_connections(self.metadata_db.clone()) + .new(false), })) } }