File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,40 @@ function mixinDiscovery(PostgreSQL) {
335335 return sql ;
336336 } ;
337337
338+ /**
339+ * Discover unique keys for a given table
340+ * @param {String } table The table name
341+ * @param {Object } options The options for discovery
342+ */
343+
344+ /*!
345+ * Retrieves a list of column names that have unique key index
346+ * @param schema
347+ * @param table
348+ * @returns {string }
349+ */
350+ PostgreSQL . prototype . buildQueryUniqueKeys = function ( schema , table ) {
351+ const sql = `
352+ SELECT
353+ a.attname AS "columnName",
354+ n.nspname AS "owner",
355+ c.relname AS "tableName"
356+ FROM pg_index i
357+ JOIN pg_class c ON c.oid = i.indrelid
358+ JOIN pg_namespace n ON n.oid = c.relnamespace
359+ JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY(i.indkey)
360+ WHERE i.indisunique = true
361+ AND i.indisprimary = false
362+ AND n.nspname = $1
363+ AND c.relname = $2
364+ ORDER BY a.attnum;
365+ ` ;
366+ return {
367+ text : sql ,
368+ values : [ schema , table ]
369+ } ;
370+ } ;
371+
338372 /**
339373 * Discover foreign keys that reference to the primary key of this table
340374 * @param {String } table The table name
You can’t perform that action at this time.
0 commit comments