You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add onUpdate and matchType to the output of analyze/read_schema (#654)
From now on `matchType` and `onUpdate` is exposed in the list of foreign
keys:
Example output for `fk_sellers` FK:
```json
"foreignKeys": {
"fk_sellers": {
"name": "fk_sellers",
"columns": [
"sellers_name",
"sellers_zip"
],
"referencedTable": "sellers",
"referencedColumns": [
"name",
"zip"
],
"onDelete": "NO ACTION",
"onUpdate": "NO ACTION",
"matchType": "SIMPLE"
}
},
```
fk_info.connameAS conname, fk_info.columnsAS columns, fk_info.relnameAS referencedTable, array_agg(ref_attr.attnameORDER BYref_attr.attname) AS referencedColumns, CASE WHEN fk_info.confdeltype='a' THEN
242
+
fk_info.connameAS conname, fk_info.columnsAS columns, fk_info.relnameAS referencedTable, array_agg(ref_attr.attnameORDER BYref_attr.attname) AS referencedColumns, CASE WHEN fk_info.confmatchtype='f' THEN
243
+
'FULL'
244
+
WHEN fk_info.confmatchtype='p' THEN
245
+
'PARTIAL'
246
+
WHEN fk_info.confmatchtype='s' THEN
247
+
'SIMPLE'
248
+
END AS matchType, CASE WHEN fk_info.confdeltype='a' THEN
243
249
'NO ACTION'
244
250
WHEN fk_info.confdeltype='r' THEN
245
251
'RESTRICT'
@@ -249,18 +255,28 @@ BEGIN
249
255
'SET DEFAULT'
250
256
WHEN fk_info.confdeltype='n' THEN
251
257
'SET NULL'
252
-
END AS onDelete FROM (
258
+
END AS onDelete, CASE WHEN fk_info.confupdtype='a' THEN
259
+
'NO ACTION'
260
+
WHEN fk_info.confupdtype='r' THEN
261
+
'RESTRICT'
262
+
WHEN fk_info.confupdtype='c' THEN
263
+
'CASCADE'
264
+
WHEN fk_info.confupdtype='d' THEN
265
+
'SET DEFAULT'
266
+
WHEN fk_info.confupdtype='n' THEN
267
+
'SET NULL'
268
+
END AS onUpdate FROM (
253
269
SELECT
254
-
fk_constraint.conname, fk_constraint.conrelid, fk_constraint.confrelid, fk_constraint.confkey, fk_cl.relname, fk_constraint.confdeltype, array_agg(fk_attr.attnameORDER BYfk_attr.attname) AS columns FROM pg_constraint AS fk_constraint
270
+
fk_constraint.conname, fk_constraint.conrelid, fk_constraint.confrelid, fk_constraint.confkey, fk_cl.relname, fk_constraint.confmatchtype, fk_constraint.confdeltype, fk_constraint.confupdtype, array_agg(fk_attr.attnameORDER BYfk_attr.attname) AS columns FROM pg_constraint AS fk_constraint
255
271
INNER JOIN pg_class fk_cl ONfk_constraint.confrelid=fk_cl.oid-- join the referenced table
name: "foreign key with ON DELETE CASCADE ON UPDATE CASCADE",
626
+
createStmt: "CREATE TABLE public.table1 (id int PRIMARY KEY); CREATE TABLE public.table2 (fk int NOT NULL, CONSTRAINT fk_fkey FOREIGN KEY (fk) REFERENCES public.table1 (id) ON DELETE CASCADE ON UPDATE CASCADE)",
name: "foreign key with MATCH full ON DELETE CASCADE",
686
+
createStmt: "CREATE TABLE public.table1 (id int PRIMARY KEY); CREATE TABLE public.table2 (fk int NOT NULL, CONSTRAINT fk_fkey FOREIGN KEY (fk) REFERENCES public.table1 (id) MATCH FULL ON DELETE CASCADE)",
0 commit comments