diff --git a/lib/datasource.js b/lib/datasource.js index f35a7774c..99dfae5e8 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1716,7 +1716,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) { columns.forEach(function(item) { const propName = nameMapper('column', item.columnName); - schema.properties[propName] = { + const propertyDetails = { type: item.type, required: !item.generated && (item.nullable === 'N' || item.nullable === 'NO' || item.nullable === 0 || item.nullable === false), @@ -1726,7 +1726,16 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) { precision: item.dataPrecision, scale: item.dataScale, generated: item.generated || false, - }; + } + if ( + item.indexType === 'BTREE' && + item.indexName !== 'PRIMARY' && + !item.isForeignKey + ) { + propertyDetails.index = {unique: true} + } + schema.properties[propName] = propertyDetails; + if (pks[item.columnName]) { schema.properties[propName].id = pks[item.columnName]; }