Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include shadowDatabaseUrl in datamodel rendering #1990

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;