Skip to content

Commit 3931fb6

Browse files
committed
feat: fetch index information for models
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent b604aa0 commit 3931fb6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/datasource.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
17161716

17171717
columns.forEach(function(item) {
17181718
const propName = nameMapper('column', item.columnName);
1719-
schema.properties[propName] = {
1719+
const propertyDetails = {
17201720
type: item.type,
17211721
required: !item.generated && (item.nullable === 'N' || item.nullable === 'NO' ||
17221722
item.nullable === 0 || item.nullable === false),
@@ -1726,13 +1726,26 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
17261726
precision: item.dataPrecision,
17271727
scale: item.dataScale,
17281728
generated: item.generated || false,
1729-
};
1729+
}
1730+
if (
1731+
item.indexType === 'BTREE' &&
1732+
item.indexName !== 'PRIMARY' &&
1733+
!item.isForeignKey
1734+
) {
1735+
propertyDetails.index = {unique: true}
1736+
}
1737+
17301738
if (pks[item.columnName]) {
1731-
schema.properties[propName].id = pks[item.columnName];
1739+
propertyDetails[propName].id = pks[item.columnName];
17321740
}
1733-
if (uniqueKeys.includes(propName)) {
1734-
schema.properties[propName]['index'] = {unique: true};
1741+
if (
1742+
uniqueKeys.includes(propName) &&
1743+
propertyDetails[propName]['index'] === undefined
1744+
) {
1745+
propertyDetails[propName]['index'] = {unique: true};
17351746
}
1747+
1748+
schema.properties[propName] = propertyDetails;
17361749
const dbSpecific = schema.properties[propName][dbType] = {
17371750
columnName: item.columnName,
17381751
dataType: item.dataType,

0 commit comments

Comments
 (0)