Skip to content

Instantly share code, notes, and snippets.

@paranoiq
Last active January 31, 2022 13:42
Show Gist options
  • Select an option

  • Save paranoiq/749ce0b3800b39b8a08ee87bb50fd397 to your computer and use it in GitHub Desktop.

Select an option

Save paranoiq/749ce0b3800b39b8a08ee87bb50fd397 to your computer and use it in GitHub Desktop.

Alter Executor

Validator rules:

Configuration

  • NoAutoincrementOnTableRule (autorepair) - disallowed changing autoincrement value
  • NoCharsetOnTablesRule (autorepair) - charset should come from parent configuration (database)
  • NoCollationOnTablesRule (autorepair) - collation sould come from parent configuration (database)
  • OnlyAsciiCharsetOnColumnRule - ascii charset is allowed for tokens, ids etc. (non-native languge data; faster comparations)
  • OnlyAsciiCollationOnColumnRule - ascii_cs collation is allowed for tokens, ids etc. (non-native languge data; faster comparations)

Context

  • ColumnExistsRule - validates that referred column exists
  • ConstraintExistsRule - validates that referred constraint exists
  • IndexExistsRule - validated that referred index exists
  • TableExistsRule - validates that referred table exists

Defaults

  • DroppedColumnHasDefaultValueRule - ensures that column has been previously correctly removed from all INSERT queries
  • NewColumnHasDefaultValueRule - ensures that previously existing INSERT queries will not start failing
  • OnlyNullDefaultValueRule - non-null default values shoul be defined by application, not in database schema

Foreign keys

  • AlwaysOnUpdateCascadeRule (autorepair) - ensures cascade rule is not ommitted
  • AlwaysOnDeleteRule - ensures cascade rule is not ommitted
  • CannotRecreateForeignKeyWithSameNameRule - cannot be done in one transaction (limitation of MySQL)
  • IndexExistsForForeignKeyRule - ensures a properly named index is created for foreign key
  • NoAutoincrementOnForeignKeyColumnsRule - ???
  • SetForeignKeyCheckOffBeforeAddingNewForeignKeyRule - do not check existing data (faster; usually a new column or table)

Indexes

  • NoDuplicitIndexesRule - disallow duplicit prefixes for multi-column indexes (can save a lot data without affecting speed)
  • NoNullableColumnsInMultiColumnUniqueKeysRule - null in unique keys behaves quite unexpectadly because null != null
  • PrimaryKeyRule - enforces explicit primary key
  • StringIndexesLengthRule - limit length of string indexes (indexes create fixed length allocations 3x the size of column length for utf8 and 4x for utf8mb4)

Locking

  • AlterAlgorithmRule (autorepair) - detects the minimal locking algorithm for ALTER (+warnings)
  • AlterLockRule (autorepair) - detexts the minimal locking algorithm for ALTER (+warnings)

Naming

  • IndexNameRule (autorepair) - standardized index naming
  • ForeignKeyConstraintNameRule (autorepair) - standardized FK naming
  • SystemVariablesSpellingRule - checks if variable exists

Privileges

  • OnlyAllowedCommandsRule - disallowes non-whitelisted commands in migrations

Readability

  • ChangeColumnSimplestWayRule (autorepair) - validate that column is change by minimal boilerplate command - most understandable what is going on (from ALTER COLUMN, MODIFY COLUMN, RENAME COLUMN...)

Types

  • CharCharsetRule - enforces charset for fixed length strings (ascii for ids and tokens)
  • DisallowedTypesRule - disallowes enum and set (should be defined by application)
  • NoAutoincrementRule - disallowes autoincrement (rule for new tables where uuid is preferred)
  • NoSizeParameterOnIntAndFloatRule (autorepair) - disallowes deprecated params for formatting
  • PrimaryKeysAllowedTypesRule - disallowes some types in PK (only int and char allowed)
  • UnsignedNumbersRule (autorepair) - warnings for signed
  • UnsignedPrimaryKeysRule (autorepair) - disallowes signed columns in PK

Syntax

  • InvalidCommandRule - syntax error catch-all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment