This script searches for paths created by foreign keys between two SQL tables.
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
~/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.
- 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.
- refactor the
find_paths
andgather_paths
functions to use an elegant graph traversal algorithm - handle nonexistent table names in arguments
- use a separate exit code for errors