|
| 1 | +package api |
| 2 | + |
| 3 | +// SQLReviewRuleType is the type of schema rule. |
| 4 | +type SQLReviewRuleType string |
| 5 | + |
| 6 | +// SQLReviewRuleLevel is the error level for SQL review rule. |
| 7 | +type SQLReviewRuleLevel string |
| 8 | + |
| 9 | +const ( |
| 10 | + // SchemaRuleTableNaming enforce the table name format. |
| 11 | + SchemaRuleTableNaming SQLReviewRuleType = "naming.table" |
| 12 | + // SchemaRuleColumnNaming enforce the column name format. |
| 13 | + SchemaRuleColumnNaming SQLReviewRuleType = "naming.column" |
| 14 | + // SchemaRulePKNaming enforce the primary key name format. |
| 15 | + SchemaRulePKNaming SQLReviewRuleType = "naming.index.pk" |
| 16 | + // SchemaRuleUKNaming enforce the unique key name format. |
| 17 | + SchemaRuleUKNaming SQLReviewRuleType = "naming.index.uk" |
| 18 | + // SchemaRuleFKNaming enforce the foreign key name format. |
| 19 | + SchemaRuleFKNaming SQLReviewRuleType = "naming.index.fk" |
| 20 | + // SchemaRuleIDXNaming enforce the index name format. |
| 21 | + SchemaRuleIDXNaming SQLReviewRuleType = "naming.index.idx" |
| 22 | + // SchemaRuleAutoIncrementColumnNaming enforce the auto_increment column name format. |
| 23 | + SchemaRuleAutoIncrementColumnNaming SQLReviewRuleType = "naming.column.auto-increment" |
| 24 | + |
| 25 | + // SchemaRuleStatementNoSelectAll disallow 'SELECT *'. |
| 26 | + SchemaRuleStatementNoSelectAll SQLReviewRuleType = "statement.select.no-select-all" |
| 27 | + // SchemaRuleStatementRequireWhere require 'WHERE' clause. |
| 28 | + SchemaRuleStatementRequireWhere SQLReviewRuleType = "statement.where.require" |
| 29 | + // SchemaRuleStatementNoLeadingWildcardLike disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed. |
| 30 | + SchemaRuleStatementNoLeadingWildcardLike SQLReviewRuleType = "statement.where.no-leading-wildcard-like" |
| 31 | + // SchemaRuleStatementDisallowCommit disallow using commit in the issue. |
| 32 | + SchemaRuleStatementDisallowCommit SQLReviewRuleType = "statement.disallow-commit" |
| 33 | + // SchemaRuleStatementDisallowLimit disallow the LIMIT clause in INSERT, DELETE and UPDATE statements. |
| 34 | + SchemaRuleStatementDisallowLimit SQLReviewRuleType = "statement.disallow-limit" |
| 35 | + // SchemaRuleStatementDisallowOrderBy disallow the ORDER BY clause in DELETE and UPDATE statements. |
| 36 | + SchemaRuleStatementDisallowOrderBy SQLReviewRuleType = "statement.disallow-order-by" |
| 37 | + // SchemaRuleStatementMergeAlterTable disallow redundant ALTER TABLE statements. |
| 38 | + SchemaRuleStatementMergeAlterTable SQLReviewRuleType = "statement.merge-alter-table" |
| 39 | + // SchemaRuleStatementInsertRowLimit enforce the insert row limit. |
| 40 | + SchemaRuleStatementInsertRowLimit SQLReviewRuleType = "statement.insert.row-limit" |
| 41 | + // SchemaRuleStatementInsertMustSpecifyColumn enforce the insert column specified. |
| 42 | + SchemaRuleStatementInsertMustSpecifyColumn SQLReviewRuleType = "statement.insert.must-specify-column" |
| 43 | + // SchemaRuleStatementInsertDisallowOrderByRand disallow the order by rand in the INSERT statement. |
| 44 | + SchemaRuleStatementInsertDisallowOrderByRand SQLReviewRuleType = "statement.insert.disallow-order-by-rand" |
| 45 | + // SchemaRuleStatementAffectedRowLimit enforce the UPDATE/DELETE affected row limit. |
| 46 | + SchemaRuleStatementAffectedRowLimit SQLReviewRuleType = "statement.affected-row-limit" |
| 47 | + // SchemaRuleStatementDMLDryRun dry run the dml. |
| 48 | + SchemaRuleStatementDMLDryRun SQLReviewRuleType = "statement.dml-dry-run" |
| 49 | + |
| 50 | + // SchemaRuleTableRequirePK require the table to have a primary key. |
| 51 | + SchemaRuleTableRequirePK SQLReviewRuleType = "table.require-pk" |
| 52 | + // SchemaRuleTableNoFK require the table disallow the foreign key. |
| 53 | + SchemaRuleTableNoFK SQLReviewRuleType = "table.no-foreign-key" |
| 54 | + // SchemaRuleTableDropNamingConvention require only the table following the naming convention can be deleted. |
| 55 | + SchemaRuleTableDropNamingConvention SQLReviewRuleType = "table.drop-naming-convention" |
| 56 | + // SchemaRuleTableCommentConvention enforce the table comment convention. |
| 57 | + SchemaRuleTableCommentConvention SQLReviewRuleType = "table.comment" |
| 58 | + // SchemaRuleTableDisallowPartition disallow the table partition. |
| 59 | + SchemaRuleTableDisallowPartition SQLReviewRuleType = "table.disallow-partition" |
| 60 | + |
| 61 | + // SchemaRuleRequiredColumn enforce the required columns in each table. |
| 62 | + SchemaRuleRequiredColumn SQLReviewRuleType = "column.required" |
| 63 | + // SchemaRuleColumnNotNull enforce the columns cannot have NULL value. |
| 64 | + SchemaRuleColumnNotNull SQLReviewRuleType = "column.no-null" |
| 65 | + // SchemaRuleColumnDisallowChangeType disallow change column type. |
| 66 | + SchemaRuleColumnDisallowChangeType SQLReviewRuleType = "column.disallow-change-type" |
| 67 | + // SchemaRuleColumnSetDefaultForNotNull require the not null column to set default value. |
| 68 | + SchemaRuleColumnSetDefaultForNotNull SQLReviewRuleType = "column.set-default-for-not-null" |
| 69 | + // SchemaRuleColumnDisallowChange disallow CHANGE COLUMN statement. |
| 70 | + SchemaRuleColumnDisallowChange SQLReviewRuleType = "column.disallow-change" |
| 71 | + // SchemaRuleColumnDisallowChangingOrder disallow changing column order. |
| 72 | + SchemaRuleColumnDisallowChangingOrder SQLReviewRuleType = "column.disallow-changing-order" |
| 73 | + // SchemaRuleColumnCommentConvention enforce the column comment convention. |
| 74 | + SchemaRuleColumnCommentConvention SQLReviewRuleType = "column.comment" |
| 75 | + // SchemaRuleColumnAutoIncrementMustInteger require the auto-increment column to be integer. |
| 76 | + SchemaRuleColumnAutoIncrementMustInteger SQLReviewRuleType = "column.auto-increment-must-integer" |
| 77 | + // SchemaRuleColumnTypeDisallowList enforce the column type disallow list. |
| 78 | + SchemaRuleColumnTypeDisallowList SQLReviewRuleType = "column.type-disallow-list" |
| 79 | + // SchemaRuleColumnDisallowSetCharset disallow set column charset. |
| 80 | + SchemaRuleColumnDisallowSetCharset SQLReviewRuleType = "column.disallow-set-charset" |
| 81 | + // SchemaRuleColumnMaximumCharacterLength enforce the maximum character length. |
| 82 | + SchemaRuleColumnMaximumCharacterLength SQLReviewRuleType = "column.maximum-character-length" |
| 83 | + // SchemaRuleColumnAutoIncrementInitialValue enforce the initial auto-increment value. |
| 84 | + SchemaRuleColumnAutoIncrementInitialValue SQLReviewRuleType = "column.auto-increment-initial-value" |
| 85 | + // SchemaRuleColumnAutoIncrementMustUnsigned enforce the auto-increment column to be unsigned. |
| 86 | + SchemaRuleColumnAutoIncrementMustUnsigned SQLReviewRuleType = "column.auto-increment-must-unsigned" |
| 87 | + // SchemaRuleCurrentTimeColumnCountLimit enforce the current column count limit. |
| 88 | + SchemaRuleCurrentTimeColumnCountLimit SQLReviewRuleType = "column.current-time-count-limit" |
| 89 | + // SchemaRuleColumnRequireDefault enforce the column default. |
| 90 | + SchemaRuleColumnRequireDefault SQLReviewRuleType = "column.require-default" |
| 91 | + |
| 92 | + // SchemaRuleSchemaBackwardCompatibility enforce the MySQL and TiDB support check whether the schema change is backward compatible. |
| 93 | + SchemaRuleSchemaBackwardCompatibility SQLReviewRuleType = "schema.backward-compatibility" |
| 94 | + |
| 95 | + // SchemaRuleDropEmptyDatabase enforce the MySQL and TiDB support check if the database is empty before users drop it. |
| 96 | + SchemaRuleDropEmptyDatabase SQLReviewRuleType = "database.drop-empty-database" |
| 97 | + |
| 98 | + // SchemaRuleIndexNoDuplicateColumn require the index no duplicate column. |
| 99 | + SchemaRuleIndexNoDuplicateColumn SQLReviewRuleType = "index.no-duplicate-column" |
| 100 | + // SchemaRuleIndexKeyNumberLimit enforce the index key number limit. |
| 101 | + SchemaRuleIndexKeyNumberLimit SQLReviewRuleType = "index.key-number-limit" |
| 102 | + // SchemaRuleIndexPKTypeLimit enforce the type restriction of columns in primary key. |
| 103 | + SchemaRuleIndexPKTypeLimit SQLReviewRuleType = "index.pk-type-limit" |
| 104 | + // SchemaRuleIndexTypeNoBlob enforce the type restriction of columns in index. |
| 105 | + SchemaRuleIndexTypeNoBlob SQLReviewRuleType = "index.type-no-blob" |
| 106 | + // SchemaRuleIndexTotalNumberLimit enforce the index total number limit. |
| 107 | + SchemaRuleIndexTotalNumberLimit SQLReviewRuleType = "index.total-number-limit" |
| 108 | + // SchemaRuleIndexPrimaryKeyTypeAllowlist enforce the primary key type allowlist. |
| 109 | + SchemaRuleIndexPrimaryKeyTypeAllowlist SQLReviewRuleType = "index.primary-key-type-allowlist" |
| 110 | + |
| 111 | + // SchemaRuleCharsetAllowlist enforce the charset allowlist. |
| 112 | + SchemaRuleCharsetAllowlist SQLReviewRuleType = "system.charset.allowlist" |
| 113 | + |
| 114 | + // SchemaRuleCollationAllowlist enforce the collation allowlist. |
| 115 | + SchemaRuleCollationAllowlist SQLReviewRuleType = "system.collation.allowlist" |
| 116 | + |
| 117 | + // SchemaRuleCommentLength limit comment length. |
| 118 | + SchemaRuleCommentLength SQLReviewRuleType = "comment.length" |
| 119 | + |
| 120 | + // SQLReviewRuleLevelError is the error level for SQL review rule. |
| 121 | + SQLReviewRuleLevelError SQLReviewRuleLevel = "ERROR" |
| 122 | + // SQLReviewRuleLevelWarning is the warning level for SQL review rule. |
| 123 | + SQLReviewRuleLevelWarning SQLReviewRuleLevel = "WARNING" |
| 124 | + // SQLReviewRuleLevelDisabled is the disabled level for SQL review rule. |
| 125 | + SQLReviewRuleLevelDisabled SQLReviewRuleLevel = "DISABLED" |
| 126 | +) |
| 127 | + |
| 128 | +// NamingRulePayload is the payload for naming rule. |
| 129 | +type NamingRulePayload struct { |
| 130 | + MaxLength int `json:"maxLength"` |
| 131 | + Format string `json:"format"` |
| 132 | +} |
| 133 | + |
| 134 | +// StringArrayTypeRulePayload is the payload for rules with string array value. |
| 135 | +type StringArrayTypeRulePayload struct { |
| 136 | + List []string `json:"list"` |
| 137 | +} |
| 138 | + |
| 139 | +// RequiredColumnRulePayload is the payload for required column rule. |
| 140 | +type RequiredColumnRulePayload struct { |
| 141 | + ColumnList []string `json:"columnList"` |
| 142 | +} |
| 143 | + |
| 144 | +// CommentConventionRulePayload is the payload for comment convention rule. |
| 145 | +type CommentConventionRulePayload struct { |
| 146 | + Required bool `json:"required"` |
| 147 | + MaxLength int `json:"maxLength"` |
| 148 | +} |
| 149 | + |
| 150 | +// NumberTypeRulePayload is the number type payload. |
| 151 | +type NumberTypeRulePayload struct { |
| 152 | + Number int `json:"number"` |
| 153 | +} |
| 154 | + |
| 155 | +// SQLReviewRule is the API message for SQL review rule. |
| 156 | +type SQLReviewRule struct { |
| 157 | + Type SQLReviewRuleType `json:"type"` |
| 158 | + Level SQLReviewRuleLevel `json:"level"` |
| 159 | + Payload string `json:"payload"` |
| 160 | +} |
0 commit comments