pub fn calculate_datamodel(
    schema: &SqlSchema,
    family: &SqlFamily,
    previous_data_model: &Datamodel,
) -> SqlIntrospectionResult<IntrospectionResult> {
    debug!("Calculating data model.");

    let mut version_check = VersionChecker::new(*family, schema);
    let mut data_model = Datamodel::new();

    // 1to1 translation of the sql schema
    introspect(schema, &mut version_check, &mut data_model, *family)?;

    // our opinionation about valid names
    sanitize_datamodel_names(&mut data_model, family);

    // deduplicating relation field names
    deduplicate_relation_field_names(&mut data_model);

    let mut warnings = vec![];
    warnings.append(&mut enrich(previous_data_model, &mut data_model, family));
    tracing::debug!("Enriching datamodel is done: {:?}", data_model);

    // commenting out models, fields, enums, enum values
    warnings.append(&mut commenting_out_guardrails(&mut data_model, family));

    // try to identify whether the schema was created by a previous Prisma version
    let version = version_check.version(&warnings, &data_model);

    // if based on a previous Prisma version add id default opinionations
    add_prisma_1_id_defaults(family, &version, &mut data_model, schema, &mut warnings);

    // renderer -> parser -> validator, is_commented_out gets lost between renderer and parser
    debug!("Done calculating data model {:?}", data_model);
    Ok(IntrospectionResult {
        data_model,
        version,
        warnings,
    })
}
/// Calculate a data model from a database schema.
Calculate a data model from a database schema.
Calculate a data model from a database schema .
pub fn calculate_datamodel(
    schema: &SqlSchema,
    family: &SqlFamily,
    previous_data_model: &Datamodel,
) -> SqlIntrospectionResult<IntrospectionResult> {
    debug!("Calculating data model.");
    let mut version_check = VersionChecker::new(*family, schema);
    let mut data_model = Datamodel::new();
    // 1to1 translation of the sql schema
    introspect(schema, &mut version_check, &mut data_model, *family)?;
    // our opinionation about valid names
    sanitize_datamodel_names(&mut data_model, family);
    // deduplicating relation field names
    deduplicate_relation_field_names(&mut data_model);
    let mut warnings = vec![];
    warnings.append(&mut enrich(previous_data_model, &mut data_model, family));
    tracing::debug!("Enriching datamodel is done: {:?}", data_model);
    // commenting out models, fields, enums, enum values
    warnings.append(&mut commenting_out_guardrails(&mut data_model, family));
    // try to identify whether the schema was created by a previous Prisma version
    let version = version_check.version(&warnings, &data_model);
    // if based on a previous Prisma version add id default opinionations
    add_prisma_1_id_defaults(family, &version, &mut data_model, schema, &mut warnings);
    // renderer -> parser -> validator, is_commented_out gets lost between renderer and parser
    debug!("Done calculating data model {:?}", data_model);
    Ok(IntrospectionResult {
        data_model,
        version,
        warnings,
    })
}
pub fn calculate_datamodel ( schema : & SqlSchema , family : & SqlFamily , previous_data_model : & Datamodel , ) -> SqlIntrospectionResult < IntrospectionResult > { debug ! ( " " ) ; let mut version_check = VersionChecker :: new ( * family , schema ) ; let mut data_model = Datamodel :: new ( ) ; // 1to1 translation of the sql schema introspect ( schema , & mut version_check , & mut data_model , * family ) ? ; // our opinionation about valid names sanitize_datamodel_names ( & mut data_model , family ) ; // deduplicating relation field names deduplicate_relation_field_names ( & mut data_model ) ; let mut warnings = vec ! [ ] ; warnings . append ( & mut enrich ( previous_data_model , & mut data_model , family ) ) ; tracing :: debug ! ( " " data_model ) ; // commenting out models, fields, enums, enum values warnings . append ( & mut commenting_out_guardrails ( & mut data_model , family ) ) ; // try to identify whether the schema was created by a previous Prisma version let version = version_check . version ( & warnings , & data_model ) ; // if based on a previous Prisma version add id default opinionations add_prisma_1_id_defaults ( family , & version , & mut data_model , schema , & mut warnings ) ; // renderer -> parser -> validator, is_commented_out gets lost between renderer and parser debug ! ( " " data_model ) ; Ok ( IntrospectionResult { data_model , version , warnings , } ) }
Calculate a data model from a database schema.
Calculate a data model from a database schema .
schema
&SqlSchema
family
&SqlFamily
previous_data_model
&Datamodel
schema
&SqlSchema
family
&SqlFamily
previous_data_model
&Datamodel