@OnlyIfDescendedFrom(['alter'])
  def visit_column_definition(self, tokens, table, column):
    """Compare ENUM modified columns.

    It is only allowed to make changes that add/remove fields from the
    end of ENUM lists.
    """
    if tokens['type']['type_type'] != 'enum':
      return

    # Coerce from ParseResults magic into a real list
    sql_values = tokens['type']['values'][:]  # From local SQL

    # Parse the DBMS derived ENUM using the SQLParser
    db_enum = column.GetType()
    try:
      db_values = parser.SQLParser._ENUM.parseString(db_enum)['values']
    except parser.pyp.ParseException:
      self.AddError(tokens, 'Column %s being converted to an enum' % column)
      return

    common_len = min(len(db_values), len(sql_values))
    if db_values[:common_len] != sql_values[:common_len]:
      self.AddError(tokens,
                    'Base ENUM lists differ: %s vs. %s' % (
                        db_values[:common_len],
                        sql_values[:common_len]))

    default = self._GetDescendants(tokens, 'default')
    if default and 'val' in default[0]:
      default_val = default[0]['val']
      if default_val and default_val[0] not in sql_values:
        self.AddError(tokens,
                      'ENUM default value %r not in values: %r' % (
                          default_val[0], sql_values))
dataset/ETHPy150Open google/mysql-tools/parser_lib/validator.py/AlterChecker.visit_column_definition/original