def restore_descriptor(self, table_name, columns, constraints, autoincrement_column=None):
<EOL>fields = []<EOL>for column in columns:<EOL><INDENT>if column.name == autoincrement_column:<EOL><INDENT>continue<EOL><DEDENT>field_type = self.restore_type(column.type)<EOL>field = {'<STR_LIT:name>': column.name, '<STR_LIT:type>': field_type}<EOL>if not column.nullable:<EOL><INDENT>field['<STR_LIT>'] = {'<STR_LIT>': True}<EOL><DEDENT>fields.append(field)<EOL><DEDENT>pk = []<EOL>for constraint in constraints:<EOL><INDENT>if isinstance(constraint, sa.PrimaryKeyConstraint):<EOL><INDENT>for column in constraint.columns:<EOL><INDENT>if column.name == autoincrement_column:<EOL><INDENT>continue<EOL><DEDENT>pk.append(column.name)<EOL><DEDENT><DEDENT><DEDENT>fks = []<EOL>if self.__dialect == '<STR_LIT>':<EOL><INDENT>for constraint in constraints:<EOL><INDENT>if isinstance(constraint, sa.ForeignKeyConstraint):<EOL><INDENT>resource = '<STR_LIT>'<EOL>own_fields = []<EOL>foreign_fields = []<EOL>for element in constraint.elements:<EOL><INDENT>own_fields.append(element.parent.name)<EOL>if element.column.table.name != table_name:<EOL><INDENT>resource = self.restore_bucket(element.column.table.name)<EOL><DEDENT>foreign_fields.append(element.column.name)<EOL><DEDENT>if len(own_fields) == len(foreign_fields) == <NUM_LIT:1>:<EOL><INDENT>own_fields = own_fields.pop()<EOL>foreign_fields = foreign_fields.pop()<EOL><DEDENT>fks.append({<EOL>'<STR_LIT>': own_fields,<EOL>'<STR_LIT>': {'<STR_LIT>': resource, '<STR_LIT>': foreign_fields},<EOL>})<EOL><DEDENT><DEDENT><DEDENT>descriptor = {}<EOL>descriptor['<STR_LIT>'] = fields<EOL>if len(pk) > <NUM_LIT:0>:<EOL><INDENT>if len(pk) == <NUM_LIT:1>:<EOL><INDENT>pk = pk.pop()<EOL><DEDENT>descriptor['<STR_LIT>'] = pk<EOL><DEDENT>if len(fks) > <NUM_LIT:0>:<EOL><INDENT>descriptor['<STR_LIT>'] = fks<EOL><DEDENT>return descriptor<EOL>
Restore descriptor from SQL