techouse / mysql-to-sqlite3

Transfer data from MySQL to SQLite
https://techouse.github.io/mysql-to-sqlite3/
MIT License
218 stars 31 forks source link

:bug: use more precise foreign key constraints #62

Closed techouse closed 11 months ago

techouse commented 11 months ago

Addresses #61

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (29ceb9f) 87.16% compared to head (cdaa3bc) 87.16%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #62 +/- ## ======================================= Coverage 87.16% 87.16% ======================================= Files 8 8 Lines 553 553 ======================================= Hits 482 482 Misses 71 71 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dethrophes commented 11 months ago

so without this change I get

2023-12-31 23:14:06 ERROR    SQLite failed creating table owners: unknown column "ERROR_NUMBER" in foreign key definition
Traceback (most recent call last):
  File "/home/jokearney/.local/bin/mysql2sqlite", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/jokearney/.local/lib/python3.8/site-packages/mysql_to_sqlite3/cli.py", line 170, in cli
    converter.transfer()
  File "/home/jokearney/.local/lib/python3.8/site-packages/mysql_to_sqlite3/transporter.py", line 614, in transfer
    self._create_table(table_name)  # type: ignore[arg-type]
  File "/home/jokearney/.local/lib/python3.8/site-packages/mysql_to_sqlite3/transporter.py", line 484, in _create_table
    self._sqlite_cur.executescript(self._build_create_table_sql(table_name))
sqlite3.OperationalError: unknown column "ERROR_NUMBER" in foreign key definition

with the code change.


2023-12-31 23:19:47 INFO     Transferring table archs
2023-12-31 23:19:48 INFO     Transferring table coids
2023-12-31 23:19:48 INFO     Transferring table customers
2023-12-31 23:19:48 INFO     Transferring table fd_stats_view
2023-12-31 23:19:48 INFO     Transferring table fdescs
2023-12-31 23:19:48 INFO     Transferring table fds
2023-12-31 23:19:48 INFO     Transferring table fds_view
2023-12-31 23:19:48 INFO     Transferring table hostnames
2023-12-31 23:19:48 INFO     Transferring table ker_types
2023-12-31 23:19:48 INFO     Transferring table ker_vers
2023-12-31 23:19:48 INFO     Transferring table machine_strs
2023-12-31 23:19:48 INFO     Transferring table os_vers
2023-12-31 23:19:48 INFO     Transferring table owner_types
2023-12-31 23:19:48 INFO     Transferring table owners
2023-12-31 23:19:48 INFO     Transferring table pnames
2023-12-31 23:19:48 INFO     Transferring table process_stats_view
2023-12-31 23:19:48 INFO     Transferring table processes
2023-12-31 23:19:48 INFO     Transferring table processes_view
2023-12-31 23:19:48 INFO     Transferring table stat_groups
2023-12-31 23:19:48 INFO     Transferring table stat_names
2023-12-31 23:19:48 INFO     Transferring table stat_types
2023-12-31 23:19:48 INFO     Transferring table stats
2023-12-31 23:19:49 INFO     Transferring table stats_view
2023-12-31 23:19:49 INFO     Transferring table system_stats_view
2023-12-31 23:19:49 INFO     Transferring table systems
2023-12-31 23:19:49 INFO     Transferring table thread_stats_view
2023-12-31 23:19:49 INFO     Transferring table threads
2023-12-31 23:19:49 INFO     Transferring table threads_view
2023-12-31 23:19:49 INFO     Transferring table tickets
2023-12-31 23:19:49 INFO     Transferring table tnames
2023-12-31 23:19:49 INFO     Transferring table trace_cfgs
2023-12-31 23:19:49 INFO     Transferring table traces
2023-12-31 23:19:49 INFO     Done!

so looks good to me.

Here is the schema that seems to be causing the issue. I've seen it on 2 systems. Server version: 8.0.35-0ubuntu0.20.04.1 - (Ubuntu)

trace_stats.zip

Note you have to be creating a new sqlite3 db to see the issue.

techouse commented 11 months ago

This has been released in v2.1.7