Skip to content

Commit

Permalink
Merge pull request #148 from zendesk/named_primary_keys
Browse files Browse the repository at this point in the history
apparently it's OK to name your primary keys.
  • Loading branch information
Ben Osheroff committed Nov 17, 2015
2 parents 8fb9ec4 + 0943974 commit addf4f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/antlr4/com/zendesk/maxwell/schema/ddl/mysql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ index_type_1:
index_or_key index_name? index_type? index_column_list index_options*;

index_type_pk:
index_constraint? PRIMARY KEY index_type? index_column_list index_options*;
index_constraint? PRIMARY KEY (index_type | index_name)* index_column_list index_options*;

index_type_3:
index_constraint? UNIQUE index_or_key index_name? index_type? index_column_list index_options*;
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/com/zendesk/maxwell/schema/ddl/DDLParserTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.zendesk.maxwell.schema.ddl;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.antlr.v4.runtime.misc.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -394,4 +392,12 @@ public void testCharsetPositionIndependence() {
create = parseCreate("CREATE TABLE `foo` (id varchar(1) character set 'foo' NOT NULL)");
assertThat(create.columns.get(0).encoding, is("foo"));
}

@Test
public void testCreateTableNamedPrimaryKey() {
/* not documented, but accepted and ignored to name the primary key. */
TableCreate create = parseCreate("CREATE TABLE db (foo char(60) binary DEFAULT '' NOT NULL, PRIMARY KEY Host (foo,Db,User))");
assertThat(create, is(notNullValue()));
assertThat(create.pks.size(), is(3));
}
}

0 comments on commit addf4f7

Please sign in to comment.