Skip to content

Commit

Permalink
Merge pull request #1990 from prisma/datamodel/shadow-database-url-re…
Browse files Browse the repository at this point in the history
…ndering

Include shadowDatabaseUrl in datamodel rendering
  • Loading branch information
tomhoule committed Jun 3, 2021
2 parents de005f7 + 48a3310 commit 7eca245
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct DatasourceSerializer {}

impl DatasourceSerializer {
pub fn add_sources_to_ast(sources: &[Datasource], ast_datamodel: &mut ast::SchemaAst) {
let mut tops: Vec<ast::Top> = Vec::new();
let mut tops: Vec<ast::Top> = Vec::with_capacity(ast_datamodel.tops.len() + sources.len());

for source in sources {
tops.push(ast::Top::Source(Self::lower_datasource(&source)))
Expand All @@ -21,6 +21,12 @@ impl DatasourceSerializer {
let mut arguments: Vec<ast::Argument> = vec![ast::Argument::new_string("provider", &source.active_provider)];

arguments.push(super::lower_string_from_env_var("url", &source.url));
if let Some((shadow_database_url, _)) = &source.shadow_database_url {
arguments.push(super::lower_string_from_env_var(
"shadowDatabaseUrl",
shadow_database_url,
))
}

ast::SourceConfig {
name: ast::Identifier::new(&source.name),
Expand Down
27 changes: 27 additions & 0 deletions libs/datamodel/core/tests/renderer/configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use datamodel::{parse_schema, render_datamodel_and_config_to_string};
use indoc::indoc;

#[test]
fn shadow_database_url_round_trips() {
let schema_str = indoc!(
r#"
datasource myds {
provider = "postgresql"
url = "postgres://"
shadowDatabaseUrl = env("EMPTY_SHADOW_DB URL_0129")
}
model Cat {
id Int @id
name String
}
"#
);

let parsed = parse_schema(schema_str).unwrap();
let (ref config, ref datamodel) = parsed.subject;

let rendered = render_datamodel_and_config_to_string(datamodel, config);

assert_eq!(schema_str, rendered);
}
1 change: 1 addition & 0 deletions libs/datamodel/core/tests/renderer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod configuration;
pub mod literals;
pub mod simplification;

0 comments on commit 7eca245

Please sign in to comment.