supatool 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sync/definitionExtractor.js +23 -16
- package/package.json +1 -1
|
@@ -927,23 +927,30 @@ async function generateCreateTableDDL(client, tableName, schemaName = 'public')
|
|
|
927
927
|
ORDER BY tc.constraint_name
|
|
928
928
|
`, [schemaName, tableName]),
|
|
929
929
|
// Get FOREIGN KEY constraints
|
|
930
|
+
// Use pg_constraint directly to avoid the N² row explosion that occurs when
|
|
931
|
+
// joining kcu × ccu on constraint_name alone for composite FKs.
|
|
930
932
|
client.query(`
|
|
931
|
-
SELECT
|
|
932
|
-
|
|
933
|
-
string_agg(
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
933
|
+
SELECT
|
|
934
|
+
c.conname AS constraint_name,
|
|
935
|
+
(SELECT string_agg(a.attname, ', ' ORDER BY u.ord)
|
|
936
|
+
FROM unnest(c.conkey) WITH ORDINALITY AS u(attnum, ord)
|
|
937
|
+
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = u.attnum
|
|
938
|
+
) AS columns,
|
|
939
|
+
fn.nspname AS foreign_table_schema,
|
|
940
|
+
fc.relname AS foreign_table_name,
|
|
941
|
+
(SELECT string_agg(a.attname, ', ' ORDER BY u.ord)
|
|
942
|
+
FROM unnest(c.confkey) WITH ORDINALITY AS u(attnum, ord)
|
|
943
|
+
JOIN pg_attribute a ON a.attrelid = c.confrelid AND a.attnum = u.attnum
|
|
944
|
+
) AS foreign_columns
|
|
945
|
+
FROM pg_constraint c
|
|
946
|
+
JOIN pg_class rel ON rel.oid = c.conrelid
|
|
947
|
+
JOIN pg_namespace nsp ON nsp.oid = rel.relnamespace
|
|
948
|
+
JOIN pg_class fc ON fc.oid = c.confrelid
|
|
949
|
+
JOIN pg_namespace fn ON fn.oid = fc.relnamespace
|
|
950
|
+
WHERE c.contype = 'f'
|
|
951
|
+
AND nsp.nspname = $1
|
|
952
|
+
AND rel.relname = $2
|
|
953
|
+
ORDER BY c.conname
|
|
947
954
|
`, [schemaName, tableName])
|
|
948
955
|
]);
|
|
949
956
|
const columnComments = new Map();
|
package/package.json
CHANGED