-
Bug
-
Resolution: Done
-
Major
-
0.8.0.Final
-
None
Debezium fails when try to add "CREATE" or "ALTER" expression with "CHECK" and "IN" constraint.
Here is my "workaround" to fix "create" definition. Probably it can make sense to create a new one field with "CHECK" constraint description on the TableEditor entity.
MySqlDdlParser#parseCreateDefinitionList
protected void parseCreateDefinitionList(Marker start, TableEditor table) { tokens.consume('('); parseCreateDefinition(start, table, false); while (tokens.canConsume(',')) { if(tokens.canConsume("CONSTRAINT", TokenStream.ANY_VALUE, "CHECK")) { consumeExpression(start); }else { parseCreateDefinition(start, table, false); } } tokens.consume(')'); }
MySqlDdlParserTest#shouldParseMultipleStatements is green after changes above.
@Test public void shouldParseMultipleStatements() { String ddl = "CREATE TABLE foo ( " + System.lineSeparator() + " c1 INTEGER NOT NULL, " + System.lineSeparator() + " c2 VARCHAR(22), " + System.lineSeparator() + "CONSTRAINT c_name CHECK (c2 IN ('A', 'B', 'C'))); " + System.lineSeparator() + "-- This is a comment" + System.lineSeparator() + "DROP TABLE foo;" + System.lineSeparator(); parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(0); // table created and dropped listener.assertNext().createTableNamed("foo").ddlStartsWith("CREATE TABLE foo ("); listener.assertNext().dropTableNamed("foo").ddlMatches("DROP TABLE foo"); }