Support postgres:// scheme in migration-engine CLI
In addition to postgresql://.
@@ -88,7 +88,7 @@ fn create_conn(
Ok((String::new(), Box::new(inner)))
}
- "postgresql" => {
+ "postgresql" | "postgres" => {
let db_name = fetch_db_name(&url, "postgres");
let connector = if admin_mode {
@@ -175,14 +175,20 @@ mod tests {
}
fn postgres_url(db: Option<&str>) -> String {
+ postgres_url_with_scheme(db, "postgresql")
+ }
+
+ fn postgres_url_with_scheme(db: Option<&str>, scheme: &str) -> String {
match std::env::var("IS_BUILDKITE") {
Ok(_) => format!(
- "postgresql://postgres:prisma@test-db-postgres:5432/{}",
- db.unwrap_or("postgres")
+ "{scheme}://postgres:prisma@test-db-postgres:5432/{db_name}",
+ scheme = scheme,
+ db_name = db.unwrap_or("postgres")
),
_ => format!(
- "postgresql://postgres:prisma@127.0.0.1:5432/{}?schema=migration-engine",
- db.unwrap_or("postgres")
+ "{scheme}://postgres:prisma@127.0.0.1:5432/{db_name}?schema=migration-engine",
+ scheme = scheme,
+ db_name = db.unwrap_or("postgres")
),
}
}
@@ -237,6 +243,17 @@ mod tests {
.unwrap();
}
+ #[test]
+ fn test_connecting_with_a_working_psql_connection_string_with_postgres_scheme() {
+ with_cli(vec!["cli", "--can_connect_to_database"], |matches| {
+ assert_eq!(
+ Ok(String::from("Connection successful")),
+ super::run(&matches, &postgres_url_with_scheme(None, "postgres"))
+ );
+ })
+ .unwrap();
+ }
+
#[test]
fn test_connecting_with_a_non_working_psql_connection_string() {
let dm = postgres_url(Some("this_does_not_exist"));
@@ -320,4 +337,13 @@ mod tests {
let db_name = super::fetch_db_name(&url, "postgres");
assert_eq!(db_name, "pgres");
}
+
+ #[test]
+ fn test_fetch_db_name_with_postgres_scheme() {
+ let url: url::Url = "postgres://postgres:prisma@127.0.0.1:5432/pgres?schema=test_schema"
+ .parse()
+ .unwrap();
+ let db_name = super::fetch_db_name(&url, "postgres");
+ assert_eq!(db_name, "pgres");
+ }
}
