Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2bda917

Browse filesBrowse files
Allow skipping the installation step during setup
For integration testing, postgresql_embedded is really useful, as it allows us to delegate handling of local instance setup and teardown, makes creating sample dbs simple, etc. However, we don't generally like to pull random binaries off of the internet, and would prefer to provide our own postgres installation paths. This also makes it easier for things like bazel and nix which we use in our dev/CI environemnts. This change just allows the setup() and new() methods to trust the installation dir that the user provided, and not try to guess an installation dir based on version, or attempt to install if the path doesn't match the version. The original behavior is still the default and how most people will use this crate.
1 parent 5423e5c commit 2bda917
Copy full SHA for 2bda917

File tree

Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed

‎postgresql_embedded/src/postgresql.rs

Copy file name to clipboardExpand all lines: postgresql_embedded/src/postgresql.rs
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ impl PostgreSQL {
5555
// conflicts with other versions. This will also facilitate setting the status of the
5656
// server to the correct initial value. If the minor and release version are not set, the
5757
// installation directory will be determined dynamically during the installation process.
58-
if let Some(version) = postgresql.settings.version.exact_version() {
59-
let path = &postgresql.settings.installation_dir;
60-
let version_string = version.to_string();
61-
62-
if !path.ends_with(&version_string) {
63-
postgresql.settings.installation_dir =
64-
postgresql.settings.installation_dir.join(version_string);
58+
if !postgresql.settings.trust_installation_dir {
59+
if let Some(version) = postgresql.settings.version.exact_version() {
60+
let path = &postgresql.settings.installation_dir;
61+
let version_string = version.to_string();
62+
63+
if !path.ends_with(&version_string) {
64+
postgresql.settings.installation_dir =
65+
postgresql.settings.installation_dir.join(version_string);
66+
}
6567
}
6668
}
67-
6869
postgresql
6970
}
7071

@@ -93,6 +94,10 @@ impl PostgreSQL {
9394
/// If it doesn't, it will search all the child directories for the latest version that matches the requirement.
9495
/// If it returns None, we couldn't find a matching installation.
9596
fn installed_dir(&self) -> Option<PathBuf> {
97+
if self.settings.trust_installation_dir {
98+
return Some(self.settings.installation_dir.clone());
99+
}
100+
96101
let path = &self.settings.installation_dir;
97102
let maybe_path_version = path
98103
.file_name()

‎postgresql_embedded/src/settings.rs

Copy file name to clipboardExpand all lines: postgresql_embedded/src/settings.rs
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub struct Settings {
5858
pub timeout: Option<Duration>,
5959
/// Server configuration options
6060
pub configuration: HashMap<String, String>,
61+
/// Skip installation and inferrence of the installation dir. Trust what the user provided.
62+
pub trust_installation_dir: bool,
6163
}
6264

6365
/// Settings implementation
@@ -109,6 +111,7 @@ impl Settings {
109111
temporary: true,
110112
timeout: Some(Duration::from_secs(5)),
111113
configuration: HashMap::new(),
114+
trust_installation_dir: false,
112115
}
113116
}
114117

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.