Skip to content
Snippets Groups Projects
Select Git revision
  • main
  • v2.0.0 protected
  • v1.1.2 protected
  • v1.1.1 protected
  • v1.1.0 protected
  • v1.0.1 protected
  • v1.0.0 protected
7 results

LICENSE

Blame
  • This project is licensed under the Creative Commons Attribution Non Commercial Share Alike 4.0 International. Learn more
    into_mappings.py 2.00 KiB
    from mitm_tooling.extraction.sql.data_models import SourceDBType
    from mitm_tooling.extraction.sql.mapping import ConceptMapping, ForeignRelation
    from mitm_tooling.representation import Header, SQLRepresentationSchema
    
    
    def sql_rep_into_mappings(header: Header, sql_rep_schema: SQLRepresentationSchema) -> list[ConceptMapping]:
        mitm_def = header.mitm_def
        cms = []
        for he in header.header_entries:
            concept_properties, relations = mitm_def.get(he.concept)
            base_table = None
            if (type_t := sql_rep_schema.type_tables.get(he.concept, {}).get(he.type_name)) is not None:
                base_table = type_t
            elif (concept_t := sql_rep_schema.concept_tables.get(he.concept)) is not None:
                base_table = concept_t
            if base_table is not None:
                cms.append(
                    ConceptMapping(
                        mitm=header.mitm,
                        concept=he.concept,
                        base_table=(SourceDBType.OriginalDB, base_table.schema, base_table.name),
                        kind_col='kind' if 'kind' in base_table.columns else None,
                        type_col=concept_properties.typing_concept,
                        identity_columns=list(relations.identity.keys()),
                        inline_relations=list(relations.inline.keys()),
                        foreign_relations={
                            fk_name: ForeignRelation(
                                fk_columns=list(fk_info.fk_relations.keys()),
                                referred_table=(SourceDBType.OriginalDB,
                                                target_concept_t.schema,
                                                target_concept_t.name),
                            ) for fk_name, fk_info in relations.foreign.items() if
                            (target_concept_t := sql_rep_schema.concept_tables.get(fk_info.target_concept)) is not None
                        },
                        attributes=list(he.attributes),
                        attribute_dtypes=list(he.attribute_dtypes),
                    )
                )
    
        return cms