def _create_table(self, mapping):
    model_name = '{}Model'.format(mapping['table'])
    mapper_kwargs = {}
    table_kwargs = {}
    self.models[mapping['table']] = type(model_name, (object,), {})
    fields = []
    mapping['oid_as_pk'] = bool(mapping.get('fields', {}).get('Id'))
    if mapping['oid_as_pk']:
        id_column = mapping['fields']['Id']
        fields.append(Column(id_column, Unicode(255), primary_key=True))
    else:
        fields.append(Column('id', Integer(), primary_key=True, autoincrement=True))
    for field in self._fields_for_mapping(mapping):
        if (mapping['oid_as_pk'] and (field['sf'] == 'Id')):
            continue
        fields.append(Column(field['db'], Unicode(255)))
    if ('record_type' in mapping):
        fields.append(Column('record_type', Unicode(255)))
    t = Table(mapping['table'], self.metadata, *fields, **table_kwargs)
    if t.exists():
        raise BulkDataException('Table already exists: {}'.format(mapping['table']))
    if (not mapping['oid_as_pk']):
        mapping['sf_id_table'] = (mapping['table'] + '_sf_id')
        if (mapping['sf_id_table'] not in self.models):
            sf_id_model_name = '{}Model'.format(mapping['sf_id_table'])
            self.models[mapping['sf_id_table']] = type(sf_id_model_name, (object,), {})
            sf_id_fields = [Column('id', Integer(), primary_key=True, autoincrement=True), Column('sf_id', Unicode(24))]
            id_t = Table(mapping['sf_id_table'], self.metadata, *sf_id_fields)
            mapper(self.models[mapping['sf_id_table']], id_t)
    mapper(self.models[mapping['table']], t, **mapper_kwargs)
def _create_table(self, mapping):
    model_name = '{}Model'.format(mapping['table'])
    mapper_kwargs = {}
    table_kwargs = {}
    self.models[mapping['table']] = type(model_name, (object,), {})
    fields = []
    mapping['oid_as_pk'] = bool(mapping.get('fields', {}).get('Id'))
    if mapping['oid_as_pk']:
        id_column = mapping['fields']['Id']
        fields.append(Column(id_column, Unicode(255), primary_key=True))
    else:
        fields.append(Column('id', Integer(), primary_key=True, autoincrement=True))
    for field in self._fields_for_mapping(mapping):
        if (mapping['oid_as_pk'] and (field['sf'] == 'Id')):
            continue
        fields.append(Column(field['db'], Unicode(255)))
    if ('record_type' in mapping):
        fields.append(Column('record_type', Unicode(255)))
    t = Table(mapping['table'], self.metadata, *fields, **table_kwargs)
    if t.exists():
        raise BulkDataException('Table already exists: {}'.format(mapping['table']))
    if (not mapping['oid_as_pk']):
        mapping['sf_id_table'] = (mapping['table'] + '_sf_id')
        if (mapping['sf_id_table'] not in self.models):
            sf_id_model_name = '{}Model'.format(mapping['sf_id_table'])
            self.models[mapping['sf_id_table']] = type(sf_id_model_name, (object,), {})
            sf_id_fields = [Column('id', Integer(), primary_key=True, autoincrement=True), Column('sf_id', Unicode(24))]
            id_t = Table(mapping['sf_id_table'], self.metadata, *sf_id_fields)
            mapper(self.models[mapping['sf_id_table']], id_t)
    mapper(self.models[mapping['table']], t, **mapper_kwargs)