diff --git a/simple_ddl_parser/ddl_parser.py b/simple_ddl_parser/ddl_parser.py index 425f828..a0c70a8 100755 --- a/simple_ddl_parser/ddl_parser.py +++ b/simple_ddl_parser/ddl_parser.py @@ -166,6 +166,14 @@ def exceptional_cases(self, value: str) -> bool: return True return False + def t_COLLATE(self, t: LexToken): + r"(?i:COLLATE|COLLATE)\b" + if not self.lexer.after_columns: + t.type = "COLLATE" + else: + t.type = "ID" + return self.set_last_token(t) + def t_AUTOINCREMENT(self, t: LexToken): r"(?i:AUTO_INCREMENT|AUTOINCREMENT)\b" if not self.lexer.after_columns: diff --git a/simple_ddl_parser/output/dialects.py b/simple_ddl_parser/output/dialects.py index 7024938..d24f826 100644 --- a/simple_ddl_parser/output/dialects.py +++ b/simple_ddl_parser/output/dialects.py @@ -86,7 +86,7 @@ class SparkSQL(Dialect): @dataclass @dialect(name="mysql") -class MySSQL(Dialect): +class MySQL(Dialect): engine: Optional[str] = field( default=None, metadata={"exclude_if_not_provided": True} ) diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py index dc7c585..c659183 100644 --- a/tests/dialects/test_mysql.py +++ b/tests/dialects/test_mysql.py @@ -592,3 +592,43 @@ def test_column_index(): ] assert result == expected + + +def test_table_properties(): + ddl = """CREATE TABLE `posts`( + `integer_column__index` INT NOT NULL INDEX + ) ENGINE=InnoDB AUTO_INCREMENT=4682 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='test';""" + + result = DDLParser(ddl).run(output_mode="mysql") + expected = [ + { + "alter": {}, + "checks": [], + "auto_increment": "4682", + "columns": [ + { + "check": None, + "default": None, + "index": True, + "name": "`integer_column__index`", + "nullable": False, + "references": None, + "size": None, + "type": "INT", + "unique": False, + } + ], + "comment": "'test'", + "default_charset": "utf8mb4", + "engine": "InnoDB", + "index": [], + "partitioned_by": [], + "primary_key": [], + "schema": None, + "table_name": "`posts`", + "tablespace": None, + "table_properties": {"collate": "utf8mb4_unicode_ci"} + } + ] + assert result == expected +