@@ -590,6 +590,56 @@ public Index getIndex() {
590590 return index ;
591591 }
592592
593+ /**
594+ * Returns the constraint kind explicitly declared or targeted by the active action. Named
595+ * DROP/ALTER CONSTRAINT actions return OTHER because their SQL does not identify the kind; no
596+ * catalogue lookup or inference from an inactive Index field is performed. Column actions
597+ * return OTHER: inspect their ColumnOption nodes for inline constraints.
598+ */
599+ public Index .Kind getConstraintKind () {
600+ if (operation == null ) {
601+ return Index .Kind .OTHER ;
602+ }
603+ switch (operation ) {
604+ case DROP_PRIMARY_KEY :
605+ case ALTER_PRIMARY_KEY :
606+ return Index .Kind .PRIMARY_KEY ;
607+ case DROP_UNIQUE :
608+ return Index .Kind .UNIQUE ;
609+ case DROP_FOREIGN_KEY :
610+ return Index .Kind .FOREIGN_KEY ;
611+ case DROP_CHECK :
612+ return Index .Kind .CHECK ;
613+ case ADD :
614+ case ALTER :
615+ if (constraintType != null && constraintSymbol != null ) {
616+ Index .Kind declared = new Index ().withType (constraintType ).getKind ();
617+ return declared .canDescribeConstraint () ? declared : Index .Kind .OTHER ;
618+ }
619+ if (operation != AlterOperation .ADD || columnName != null
620+ || colDataTypeList != null || constraintName != null || oldIndex != null
621+ || commentText != null || columnSetNotNullList != null
622+ || columnDropNotNullList != null
623+ || columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()) {
624+ return Index .Kind .OTHER ;
625+ }
626+ if (index != null ) {
627+ return index .getKind () != null && index .getKind ().canDescribeConstraint ()
628+ ? index .getKind ()
629+ : Index .Kind .OTHER ;
630+ }
631+ if (pkColumns != null ) {
632+ return Index .Kind .PRIMARY_KEY ;
633+ }
634+ if (ukColumns != null ) {
635+ return Index .Kind .UNIQUE ;
636+ }
637+ return fkColumns != null ? Index .Kind .FOREIGN_KEY : Index .Kind .OTHER ;
638+ default :
639+ return Index .Kind .OTHER ;
640+ }
641+ }
642+
593643 public void setIndex (Index index ) {
594644 this .index = index ;
595645 }
0 commit comments