Skip to content

Commit

Permalink
Include shadowDatabaseUrl in datamodel rendering
Browse files Browse the repository at this point in the history
It was previously not included in the lowering of the datamodel to an
AST (after introspection).

closes prisma/prisma#7337
  • Loading branch information
tomhoule committed Jun 3, 2021
1 parent de005f7 commit 48a3310
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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
@@ -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
@@ -1,2 +1,3 @@
pub mod configuration;
pub mod literals;
pub mod simplification;

0 comments on commit 48a3310

Please sign in to comment.