Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pg stmt cache #828

Merged
merged 3 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions libs/test-setup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn postgres_9_url(db_name: &str) -> String {
let (host, port) = db_host_and_port_postgres_9();

format!(
"postgresql://postgres:prisma@{}:{}/{}?schema={}",
"postgresql://postgres:prisma@{}:{}/{}?schema={}&statement_cache_size=0",
host, port, db_name, SCHEMA_NAME
)
}
Expand All @@ -56,7 +56,7 @@ pub fn postgres_10_url(db_name: &str) -> String {
let (host, port) = db_host_and_port_postgres_10();

format!(
"postgresql://postgres:prisma@{}:{}/{}?schema={}",
"postgresql://postgres:prisma@{}:{}/{}?schema={}&statement_cache_size=0",
host, port, db_name, SCHEMA_NAME
)
}
Expand All @@ -65,7 +65,7 @@ pub fn postgres_11_url(db_name: &str) -> String {
let (host, port) = db_host_and_port_postgres_11();

format!(
"postgresql://postgres:prisma@{}:{}/{}?schema={}",
"postgresql://postgres:prisma@{}:{}/{}?schema={}&statement_cache_size=0",
host, port, db_name, SCHEMA_NAME
)
}
Expand All @@ -74,7 +74,7 @@ pub fn postgres_12_url(db_name: &str) -> String {
let (host, port) = db_host_and_port_postgres_12();

format!(
"postgresql://postgres:prisma@{}:{}/{}?schema={}",
"postgresql://postgres:prisma@{}:{}/{}?schema={}&statement_cache_size=0",
host, port, db_name, SCHEMA_NAME
)
}
Expand Down
1 change: 1 addition & 0 deletions migration-engine/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ thiserror = "1.0.9"
tracing = "0.1.10"
tracing-futures = "0.2.0"
tracing-error = "0.1.2"
url = "2"

[features]
default = ["sql"]
Expand Down
24 changes: 23 additions & 1 deletion migration-engine/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,29 @@ pub async fn migration_api(datamodel: &str) -> CoreResult<Arc<dyn api::GenericAp

let connector = match source.connector_type() {
#[cfg(feature = "sql")]
provider if [MYSQL_SOURCE_NAME, POSTGRES_SOURCE_NAME, SQLITE_SOURCE_NAME].contains(&provider) => {
provider if POSTGRES_SOURCE_NAME == provider => {
let mut u = url::Url::parse(&source.url().value).unwrap();

let params: Vec<(String, String)> = u.query_pairs().map(|(k, v)| (k.to_string(), v.to_string())).collect();

u.query_pairs_mut().clear();

for (k, v) in params.into_iter() {
if k == "statement_cache_size" {
u.query_pairs_mut().append_pair("statement_cache_size", "0");
} else {
u.query_pairs_mut().append_pair(&k, &v);
}
}

if !u.query_pairs().any(|(k, _)| k == "statement_cache_size") {
u.query_pairs_mut().append_pair("statement_cache_size", "0");
}

SqlMigrationConnector::new(u.as_str()).await?
}
#[cfg(feature = "sql")]
provider if [MYSQL_SOURCE_NAME, SQLITE_SOURCE_NAME].contains(&provider) => {
SqlMigrationConnector::new(&source.url().value).await?
}
x => unimplemented!("Connector {} is not supported yet", x),
Expand Down