https://github.com/pawel-slowik/sql-fk-path
Search for paths created by foreign keys between two SQL tables.
https://github.com/pawel-slowik/sql-fk-path
cli foreign-key sql
Last synced: 14 days ago
JSON representation
Search for paths created by foreign keys between two SQL tables.
- Host: GitHub
- URL: https://github.com/pawel-slowik/sql-fk-path
- Owner: pawel-slowik
- License: mit
- Created: 2023-05-27T16:01:50.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T17:06:21.000Z (over 1 year ago)
- Last Synced: 2025-02-19T18:23:04.121Z (over 1 year ago)
- Topics: cli, foreign-key, sql
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Build Status][build-badge]
[build-badge]: https://github.com/pawel-slowik/sql-fk-path/workflows/tests/badge.svg
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][sqlalchemy] installed:
pip3 install -r requirements.txt
You will also need to install a [SQLAlchemy dialect][sqlalchemy-dialect]
suitable for your database:
pip3 install mysqlclient
[sqlalchemy]:https://www.sqlalchemy.org/
[sqlalchemy-dialect]:https://docs.sqlalchemy.org/en/latest/dialects/index.html
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][mysql-database-is-schema] and [MariaDB][mariadb-database-is-schema] 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.
[mysql-database-is-schema]:https://dev.mysql.com/doc/refman/8.0/en/create-database.html
[mariadb-database-is-schema]:https://mariadb.com/kb/en/create-database/
## 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