omymodels icon indicating copy to clipboard operation
omymodels copied to clipboard

ddl with DEFAULT CHARSET leads to `ValueError: Found ALTER statement to not existed TABLE`

Open hrehfeld opened this issue 2 years ago • 1 comments

Describe the bug ddl with DEFAULT CHARSET leads to

Traceback (most recent call last):
  File "/home/hrehfeld/projects/ext/omymodels/.venv/bin/omm", line 8, in <module>
    sys.exit(main())
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/omymodels/cli.py", line 76, in main
    result = create_models(
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/omymodels/from_ddl.py", line 45, in create_models
    data = get_tables_information(ddl, ddl_path)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/omymodels/from_ddl.py", line 26, in get_tables_information
    tables = parse_from_file(ddl_file, group_by_type=True)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/ddl_parser.py", line 231, in parse_from_file
    return DDLParser(df.read(), **(parser_settings or {})).run(file_path=file_path, **kwargs)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/parser.py", line 346, in run
    self.tables = result_format(self.tables, output_mode, group_by_type)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/output/common.py", line 181, in result_format
    tables_dict = process_alter_and_index_result(
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/output/common.py", line 145, in process_alter_and_index_result
    tables_dict = add_alter_to_table(tables_dict, table)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/output/common.py", line 80, in add_alter_to_table
    target_table = get_table_from_tables_data(tables_dict, table_id)
  File "/home/hrehfeld/projects/ext/omymodels/.venv/lib/python3.10/site-packages/simple_ddl_parser/output/common.py", line 29, in get_table_from_tables_data
    raise ValueError(
ValueError: Found ALTER statement to not existed TABLE `option` with SCHEMA None

To Reproduce use this ddl:

CREATE TABLE `option` (
  `opt_id` int(10) UNSIGNED NOT NULL,
) DEFAULT CHARSET=utf8;

ALTER TABLE `option`
  ADD PRIMARY KEY (`opt_id`);

then just omm option.sql.

This runs without error:

CREATE TABLE `option` (
  `opt_id` int(10) UNSIGNED NOT NULL,
) CHARSET=utf8;

ALTER TABLE `option`
  ADD PRIMARY KEY (`opt_id`);

pretty sure this is valid mysql syntax: https://dev.mysql.com/doc/refman/8.0/en/create-table.html

** version ** omymodels-0.13.0

hrehfeld avatar Jun 23 '23 13:06 hrehfeld

problem in simple-ddl-parser - it does not support it, I will create ticket for this in https://github.com/xnuinside/simple-ddl-parser

xnuinside avatar Aug 17 '23 08:08 xnuinside

this issue was fixed, works with simple-ddl-parser 1.3.0

xnuinside avatar May 12 '24 12:05 xnuinside