diff --git a/lib/discovery.js b/lib/discovery.js index a9cf6c2c..c60cd553 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -298,6 +298,29 @@ function mixinDiscovery(MySQL, mysql) { return sql; }; + /** + * Discover unique keys for a given table + * @param {String} table The table name + * @param {Object} options The options for discovery + */ + + /*! + * Retrieves a list of column names that have unique key index + * @param schema + * @param table + * @returns {string} + */ + MySQL.prototype.buildQueryUniqueKeys = function(schema, table) { + const sql = 'SELECT Column_name AS "columnName",' + + ' table_schema AS "owner",' + + ' table_name AS "tableName"' + + ' FROM Information_schema.statistics' + + ' WHERE Table_schema = ' + mysql.escape(schema) + + ' AND Table_name = ' + mysql.escape(table) + + ' AND Non_unique = 0 AND Index_name <> \'PRIMARY\';'; + return sql; + } + /** * Discover foreign keys that reference to the primary key of this table * @param {String} table The table name