diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go index 77931bc83b85..49e4a23c7d00 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go @@ -13,6 +13,7 @@ package scbuildstmt import ( "sort" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -246,6 +247,12 @@ func dropColumn( undroppedSeqBackrefsToCheck.Add(e.SequenceID) } case *scpb.FunctionBody: + // Until the appropriate version gate is hit, we still do not allow + // dropping function bodies. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping functions is"+ + "not allowed yet.")) + } if behavior != tree.DropCascade { _, _, fnName := scpb.FindFunctionName(b.QueryByID(e.FunctionID)) panic(sqlerrors.NewDependentObjectErrorf( @@ -255,6 +262,12 @@ func dropColumn( } dropCascadeDescriptor(b, e.FunctionID) case *scpb.UniqueWithoutIndexConstraint: + // Until the appropriate version gate is hit, we still do not allow + // dropping unique without index constraints. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping without"+ + "index constraints is not allowed.")) + } constraintElems := b.QueryByID(e.TableID).Filter(hasConstraintIDAttrFilter(e.ConstraintID)) _, _, constraintName := scpb.FindConstraintWithoutIndexName(constraintElems.Filter(publicTargetFilter)) alterTableDropConstraint(b, tn, tbl, &tree.AlterTableDropConstraint{ @@ -263,6 +276,12 @@ func dropColumn( DropBehavior: behavior, }) case *scpb.UniqueWithoutIndexConstraintUnvalidated: + // Until the appropriate version gate is hit, we still do not allow + // dropping unique without index constraints. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping without"+ + "index constraints is not allowed.")) + } constraintElems := b.QueryByID(e.TableID).Filter(hasConstraintIDAttrFilter(e.ConstraintID)) _, _, constraintName := scpb.FindConstraintWithoutIndexName(constraintElems.Filter(publicTargetFilter)) alterTableDropConstraint(b, tn, tbl, &tree.AlterTableDropConstraint{ diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go index 05a6956b1dea..80f61e244f0f 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go @@ -13,11 +13,13 @@ package scbuildstmt import ( "fmt" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice" "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -235,6 +237,12 @@ func maybeDropDependentFKConstraints( // shouldDropFK returns true if it is a dependent FK and no uniqueness-providing // replacement can be found. shouldDropFK := func(fkReferencedColIDs []catid.ColumnID) bool { + // Until the appropriate version gate is hit, we still do not allow + // dropping foreign keys in any the context of secondary indexes. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping FK constraints"+ + " as a result of `DROP INDEX CASCADE` is not supported yet.")) + } return canToBeDroppedConstraintServeFK(fkReferencedColIDs) && !hasColsUniquenessConstraintOtherThan(b, tableID, fkReferencedColIDs, toBeDroppedConstraintID) }