Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set all datamodel-related flags in structopt
- Loading branch information
Julius de Bruijn
committed
Mar 20, 2020
1 parent
2f92b67
commit a0c4a9e
Showing
11 changed files
with
198 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::{PrismaError, PrismaResult}; | ||
use serde::Deserialize; | ||
use serde_json; | ||
|
||
/// Loads data model components for the v2 data model. | ||
/// The v2 data model is provided either as file (PRISMA_DML_PATH) or as string in the env (PRISMA_DML). | ||
/// Attempts to construct a Prisma v2 datamodel. | ||
/// Returns: DatamodelV2Components | ||
/// Err If a source for v2 was found, but conversion failed. | ||
/// Ok(Some) If a source for v2 was found, and the conversion suceeded. | ||
/// Ok(None) If no source for a v2 data model was found. | ||
pub fn load( | ||
dml_string: &str, | ||
datasource_overwrites: Option<String>, | ||
ignore_env_var_errors: bool, | ||
) -> PrismaResult<datamodel::Configuration> { | ||
let config_result = if ignore_env_var_errors { | ||
datamodel::parse_configuration_and_ignore_env_errors(&dml_string) | ||
} else { | ||
datamodel::parse_configuration(&dml_string) | ||
}; | ||
|
||
match config_result { | ||
Err(errors) => Err(PrismaError::ConversionError(errors, dml_string.to_string())), | ||
Ok(mut configuration) => { | ||
if let Some(overwrites) = datasource_overwrites { | ||
let datasource_overwrites: Vec<SourceOverride> = serde_json::from_str(&overwrites)?; | ||
|
||
for datasource_override in datasource_overwrites { | ||
for datasource in &mut configuration.datasources { | ||
if &datasource_override.name == datasource.name() { | ||
debug!( | ||
"overwriting datasource {} with url {}", | ||
&datasource_override.name, &datasource_override.url | ||
); | ||
datasource.set_url(&datasource_override.url); | ||
} | ||
} | ||
} | ||
} | ||
Ok(configuration) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct SourceOverride { | ||
name: String, | ||
url: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.