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.
@@ -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
- tc.constraint_name,
933
- string_agg(kcu.column_name, ', ' ORDER BY kcu.ordinal_position) as columns,
934
- ccu.table_schema AS foreign_table_schema,
935
- ccu.table_name AS foreign_table_name,
936
- string_agg(ccu.column_name, ', ' ORDER BY kcu.ordinal_position) as foreign_columns
937
- FROM information_schema.table_constraints tc
938
- JOIN information_schema.key_column_usage kcu
939
- ON tc.constraint_name = kcu.constraint_name AND tc.table_schema = kcu.table_schema
940
- JOIN information_schema.constraint_column_usage ccu
941
- ON tc.constraint_name = ccu.constraint_name AND tc.table_schema = ccu.table_schema
942
- WHERE tc.table_schema = $1
943
- AND tc.table_name = $2
944
- AND tc.constraint_type = 'FOREIGN KEY'
945
- GROUP BY tc.constraint_name, ccu.table_schema, ccu.table_name
946
- ORDER BY tc.constraint_name
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supatool",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "CLI for PostgreSQL (Cloud SQL / Supabase): extract schema to files, deploy schema diffs, apply migrations, seed export.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",