# mysql-fk-export

Anchor on a set of rows or table in a MySQL database and generate `CREATE TABLE` and `INSERT` statement necessary to fully import those rows and tables into another database, respecting all foreign key constraints.

### Setup

1. Copy over config template
```bash
cp .env.shadow .env
```

2. Fill in database details


### Running

1. Build container image

```bash
docker compose build cli
```

2. Run container image

Generate `CREATE TABLE` statements

```bash
docker compose run --rm cli track
```

Generate `CREATE TABLE` and `INSERT` statements

```bash
docker compose run --rm cli track --column release_id --values 1 2 3
```

Reference:
```bash
usage: main.py [-h] [--column COLUMN] [--values VALUES [VALUES ...]] table

positional arguments:
  table                 name of table to anchor on

options:
  -h, --help            show this help message and exit
  --column COLUMN       column to search for data on (default: None)
  --values VALUES [VALUES ...]
                        values to filter column on (default: None)
```