github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/schema_feature_name.go (about)

     1  // Copyright 2021 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package tree
    12  
    13  import "strings"
    14  
    15  // SchemaFeatureName feature name for a given statement, which can be used
    16  // to detect via the feature check functions if the schema change is allowed.
    17  type SchemaFeatureName string
    18  
    19  // GetSchemaFeatureNameFromStmt takes a statement and converts it to a schema
    20  // feature name, which can be enabled or disabled via a feature flag.
    21  func GetSchemaFeatureNameFromStmt(stmt Statement) SchemaFeatureName {
    22  	statementTag := stmt.StatementTag()
    23  	statementInfo := strings.Split(statementTag, " ")
    24  
    25  	switch stmt.(type) {
    26  	case *CommentOnDatabase, *CommentOnSchema, *CommentOnTable,
    27  		*CommentOnColumn, *CommentOnIndex, *CommentOnConstraint, *DropOwnedBy:
    28  		return SchemaFeatureName(statementTag)
    29  	}
    30  	// Only grab the first two words (i.e. ALTER TABLE, etc..).
    31  	if len(statementInfo) >= 2 {
    32  		return SchemaFeatureName(statementInfo[0] + " " + statementInfo[1])
    33  	}
    34  	return SchemaFeatureName(statementInfo[0])
    35  }