File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
pkg/workload/schemachange Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -289,7 +289,8 @@ func (og *operationGenerator) columnIsDependedOn(
289
289
// so performing unions and joins is easier.
290
290
//
291
291
// To check if any foreign key references exist to this table, we use pg_constraint
292
- // and check if any columns are dependent.
292
+ // and check if any columns are dependent. We check both confrelid (table is referenced)
293
+ // and self-referential foreign keys (where conrelid = confrelid).
293
294
return og .scanBool (ctx , tx , `SELECT EXISTS(
294
295
SELECT source.column_id
295
296
FROM (
@@ -318,6 +319,12 @@ func (og *operationGenerator) columnIsDependedOn(
318
319
FROM pg_catalog.pg_constraint
319
320
WHERE confrelid = $1::REGCLASS
320
321
)
322
+ UNION (
323
+ SELECT unnest(conkey) AS column_id
324
+ FROM pg_catalog.pg_constraint
325
+ WHERE conrelid = $1::REGCLASS
326
+ AND confrelid = $1::REGCLASS
327
+ )
321
328
) AS cons
322
329
INNER JOIN (
323
330
SELECT ordinal_position AS column_id
You can’t perform that action at this time.
0 commit comments