pawel-slowik / sql-fk-path

Search for paths created by foreign keys between two SQL tables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

This script searches for paths created by foreign keys between two SQL tables.

Installation

Clone this repository and make sure you have Python 3.x and SQLAlchemy installed:

pip3 install -r requirements.txt

You will also need to install a SQLAlchemy dialect suitable for your database:

pip3 install mysqlclient

With Docker:

docker-compose build

Example usage

~/path/sqlfkpath.py mysql://user:password@host/database begin_table end_table

With Docker:

docker-compose run --rm cmd ./sqlfkpath.py mysql://user:password@host/database begin_table end_table

The script will exit with code 0 if there's at least one path found and with code 1 if there are no paths.

Limitations

  • The script will try to discover foreign key constraints in all available schemas. This is necessary because a constraint linking two tables could be placed in a schema that is separate from the linked tables. Since for MySQL and MariaDB a schema is synonymous with a database, this means that for these systems the script will inspect all databases. There is currently no way to disable that behaviour.

TODO

  • refactor the find_paths and gather_paths functions to use an elegant graph traversal algorithm
  • handle nonexistent table names in arguments
  • use a separate exit code for errors

About

Search for paths created by foreign keys between two SQL tables.

License:MIT License


Languages

Language:Python 99.1%Language:Dockerfile 0.9%