(self, couch_class, prefix=None)
Iterate through the Couch schema to add missing fields and check field types match
Iterate through the Couch schema to add missing fields and check field types match
Iterate through the Couch schema to add missing fields and check field types match
def correlate_with_couch_schema(self, couch_class, prefix=None):
        """Iterate through the Couch schema to add missing fields and check field types match
        """
        for name, field in couch_class.properties().items():
            if name in self.COUCH_FIELDS:
                continue

            name = f'{prefix}.{name}' if prefix else name
            schema_type = self.couch_type_to_sql_type(field)
            data_type = self.field_type(name)
            if data_type is None:
                self.init_field(name, schema_type)
                continue

            if data_type == self.FIELD_TYPE_UNKNOWN:
                self.update_field_type(name, self.couch_type_to_sql_type(schema_type))
                continue

            if data_type != schema_type and data_type != self.FIELD_TYPE_JSON:
                print(f"WARNING: type mismatch for {name}. "
                      f"Type from data '{data_type}' != type from schema '{schema_type}'")

            if data_type in (self.FIELD_TYPE_SUBMODEL_DICT, self.FIELD_TYPE_SUBMODEL_LIST):
                if isinstance(field, schema.SchemaProperty):
                    self.correlate_with_couch_schema(field.item_type, prefix=name)
                elif isinstance(field, schema.SchemaDictProperty):
                    self.correlate_with_couch_schema(field._type, prefix=name)
def correlate_with_couch_schema ( self , couch_class , prefix = None ) : for name , field in couch_class . properties ( ) . items ( ) : if name in self . COUCH_FIELDS : continue name = f'{prefix}.{name}' if prefix else name schema_type = self . couch_type_to_sql_type ( field ) data_type = self . field_type ( name ) if data_type is None : self . init_field ( name , schema_type ) continue if data_type == self . FIELD_TYPE_UNKNOWN : self . update_field_type ( name , self . couch_type_to_sql_type ( schema_type ) ) continue if data_type != schema_type and data_type != self . FIELD_TYPE_JSON : print ( f"WARNING: type mismatch for {name}. " f"Type from data '{data_type}' != type from schema '{schema_type}'" ) if data_type in ( self . FIELD_TYPE_SUBMODEL_DICT , self . FIELD_TYPE_SUBMODEL_LIST ) : if isinstance ( field , schema . SchemaProperty ) : self . correlate_with_couch_schema ( field . item_type , prefix = name ) elif isinstance ( field , schema . SchemaDictProperty ) : self . correlate_with_couch_schema ( field . _type , prefix = name )