Skip to content

Commit

Permalink
Separate Introspection warnings to its own module (#3633)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn authored Jan 27, 2023
1 parent 61863c7 commit a99c688
Show file tree
Hide file tree
Showing 396 changed files with 2,433 additions and 2,783 deletions.
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl MongoDbIntrospectionConnector {

ConnectorError {
user_facing_error: Some(known),
kind: introspection_connector::ErrorKind::InvalidDatabaseUrl(format!("{} in database URL", err)),
kind: introspection_connector::ErrorKind::InvalidDatabaseUrl(format!("{err} in database URL")),
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl fmt::Display for FieldType {
FieldType::Int64 => f.write_str("BigInt"),
FieldType::Json => f.write_str("Json"),
FieldType::Document(s) => f.write_str(s),
FieldType::Array(r#type) => write!(f, "Array({})", r#type),
FieldType::Unsupported(r#type) => write!(f, "{}", r#type),
FieldType::Array(r#type) => write!(f, "Array({type})"),
FieldType::Unsupported(r#type) => write!(f, "{type}"),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ impl<'a> Statistics<'a> {
/// - if model is foo and field is bar, the type is FooBar
/// - if a model already exists with the name, we'll use FooBar_
fn composite_type_name(&self, model: &str, field: &str) -> Name {
let combined: String = format!("{}_{}", model, field)
.chars()
.filter(|c| c.is_ascii())
.collect();
let combined: String = format!("{model}_{field}").chars().filter(|c| c.is_ascii()).collect();

let name = Name::Model(combined.to_case(Case::Pascal));

let name = if self.models.contains_key(&name) {
format!("{}_", name)
format!("{name}_")
} else {
name.take()
};
Expand Down Expand Up @@ -568,7 +565,7 @@ impl fmt::Display for FieldPercentages {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (i, (k, v)) in self.data.iter().enumerate() {
let p = (*v * 1000.0).round() / 10.0;
write!(f, "{}: {}%", k, p)?;
write!(f, "{k}: {p}%")?;

if i < self.data.keys().count() - 1 {
write!(f, ", ")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ where

let features = preview_features
.iter()
.map(|f| format!("\"{}\"", f))
.map(|f| format!("\"{f}\""))
.collect::<Vec<_>>()
.join(", ");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,24 @@
mod context;

use crate::{rendering, warnings, SqlFamilyTrait, SqlIntrospectionResult};
pub(crate) use context::{InputContext, OutputContext};
use crate::{rendering, warnings, SqlIntrospectionResult};
pub(crate) use context::DatamodelCalculatorContext;
use introspection_connector::{IntrospectionContext, IntrospectionResult, Version};

use sql_schema_describer as sql;

/// Calculate a data model from a database schema.
pub fn calculate(schema: &sql::SqlSchema, ctx: &IntrospectionContext) -> SqlIntrospectionResult<IntrospectionResult> {
let introspection_map = Default::default();
let ctx = DatamodelCalculatorContext::new(ctx, schema);

let mut input = InputContext {
version: Version::NonPrisma,
config: ctx.configuration(),
render_config: ctx.render_config,
schema,
sql_family: ctx.sql_family(),
previous_schema: ctx.previous_schema(),
introspection_map: &introspection_map,
force_namespaces: ctx.namespaces(),
};

let introspection_map = crate::introspection_map::IntrospectionMap::new(input);
input.introspection_map = &introspection_map;

let mut output = OutputContext {
rendered_schema: datamodel_renderer::Datamodel::default(),
warnings: warnings::Warnings::new(),
};

input.version = crate::version_checker::check_prisma_version(&input);

let (schema_string, is_empty) = rendering::to_psl_string(input, &mut output)?;
let warnings = output.finalize_warnings();
let (schema_string, is_empty) = rendering::to_psl_string(&ctx)?;
let warnings = warnings::generate(&ctx);

// Warning codes 5 and 6 are for Prisma 1 default reintrospection.
let version = if warnings.iter().any(|w| ![5, 6].contains(&w.code)) {
Version::NonPrisma
} else {
input.version
ctx.version
};

Ok(IntrospectionResult {
Expand Down
Loading

0 comments on commit a99c688

Please sign in to comment.