mysql-to-sqlite3 icon indicating copy to clipboard operation
mysql-to-sqlite3 copied to clipboard

:sparkles: add table creation order computation with FK constraints

Open techouse opened this issue 4 months ago • 4 comments

This pull request introduces enhancements to the MySQL-to-SQLite data transfer process, focusing on foreign key handling, schema metadata extraction, and table creation order computation. Additionally, unit tests have been expanded to ensure robust functionality and edge case coverage.

Enhancements to MySQL-to-SQLite data transfer:

  • Foreign key handling during transfer:

    • Added computation of table creation order to respect foreign key constraints using the new compute_creation_order function. Tables are processed in a dependency-safe order, and cyclic dependencies are logged as warnings.
    • Implemented a post-transfer check for foreign key constraint violations in SQLite using PRAGMA foreign_key_check. Violations are logged for debugging purposes.
  • Schema metadata extraction:

    • Introduced the fetch_schema_metadata function to retrieve table names and foreign key relationships from the MySQL schema. This ensures robust handling of various row formats and edge cases.

Codebase improvements:

  • Topological sorting for table creation:
    • Added the topo_sort_tables function to perform topological sorting of tables based on foreign key dependencies. This ensures tables are created in a foreign key-safe order. Cyclic dependencies are identified and returned for further analysis.

Unit test enhancements:

  • Expanded test coverage for new functionality:
    • Added tests for topo_sort_tables to verify behavior with acyclic, cyclic, and empty dependency graphs.
    • Added tests for fetch_schema_metadata to ensure robust handling of diverse row formats, including tuples, lists, objects, dictionaries, and invalid types.
    • Added tests for compute_creation_order to validate table ordering and cycle detection in schemas with and without circular dependencies.
    • Enhanced transfer method tests to verify foreign key checks and exception handling during SQLite operations.

techouse avatar Jun 08 '25 18:06 techouse