Metadata-Version: 2.5
Name: sqlseed-cli
Version: 0.2.7
Summary: Command-line interface for sqlseed test data generation, preview and configuration replay
Project-URL: Documentation, https://sunbos.github.io/sqlseed/guide/
Project-URL: Homepage, https://github.com/sunbos/sqlseed
Project-URL: Repository, https://github.com/sunbos/sqlseed/tree/main/plugins/sqlseed-cli
Author-email: SunBo <1443584939@qq.com>
License-Expression: AGPL-3.0-or-later
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Requires-Dist: click>=8.0
Requires-Dist: rich>=13.0
Requires-Dist: sqlseed<0.3,>=0.2.5.dev0
Description-Content-Type: text/markdown

# sqlseed-cli

Command-line interface for [sqlseed](https://sunbos.github.io/sqlseed/): generate
SQLite and PostgreSQL test data, preview samples, inspect schema, and save or replay
configuration. This package provides the `sqlseed` command.

## Installation

These instructions target version 0.2.7. Check [Releases](https://github.com/sunbos/sqlseed/releases)
for publication status; use the source installation below to test an unpublished candidate.
Use a Python 3.10+ virtual environment:

```bash
python -m pip install "sqlseed-cli==0.2.7"
```

Core 0.2.4 and older lack the shared diagnostic interfaces required by this version.
For development, install Core and the required local plugins together from the
repository root:

```bash
python -m pip install -e . -e ./plugins/sqlseed-cli
```

For AI commands in a source checkout, install all three local packages together:

```bash
python -m pip install -e . -e ./plugins/sqlseed-cli -e ./plugins/sqlseed-ai
```

Installing only `sqlseed` provides the Python API. Install `sqlseed-cli` or the Core
`cli` extra to get the console command. Faker is included with Core; Mimesis is
optional. The examples below select the installed Faker provider explicitly.

## Usage

Create your tables first, then run:

```bash
sqlseed fill app.db -t users -n 1000 --provider faker --no-ai
sqlseed preview app.db -t users -n 5 --provider faker
sqlseed inspect app.db --table users --show-mapping
sqlseed init generate.yaml --db app.db
sqlseed fill app.db -t users -n 100 --provider faker --no-ai --snapshot
sqlseed replay <cache_dir>/snapshots/YYYY-MM-DD_HHMMSS_ffffff_users.yaml
```

| Command | Purpose |
|---|---|
| `fill` | Generate and write data into existing tables |
| `preview` | Generate samples without writing them |
| `inspect` | Show schema and column mapping |
| `init` | Write a YAML configuration template |
| `replay` | Run a saved configuration snapshot |

`init` rejects an output path that aliases its source SQLite file, including symbolic and hard links. Use a separate configuration path; replacing an existing configuration remains supported. The check covers existing ordinary local files, not concurrent path changes or custom SQLite VFS targets.

For PostgreSQL, install the Core `postgres` extra and use `--url`:

```bash
python -m pip install "sqlseed[postgres]==0.2.7" "sqlseed-cli==0.2.7"
sqlseed fill --url "postgresql+psycopg://user:pass@host/db" -t users -n 1000 --provider faker --no-ai
sqlseed inspect --url "postgresql+psycopg://user:pass@host/db"
```

For configuration-driven generation, put exactly one of `db_path` or `url` in the YAML.
Set `provider: faker` in a generated template, or install the optional Mimesis provider
if the template uses `provider: mimesis`:

```bash
sqlseed fill --config generate.yaml --no-ai
```

`--config` cannot be combined with a positional database path or `--url`. Omitted
`--provider`, `--locale`, and `--batch-size` preserve the YAML values. Explicit options
override those values, including options equal to the command defaults. Without
`--config`, the defaults are `mimesis`, `en_US`, and `5000`.

If the configuration file cannot be read, parsed, or validated, `fill` reports the
reason and exits with status 2 before generation or clearing tables. Correct the
file path, UTF-8 YAML/JSON syntax, or reported fields and retry.
Each invocation reads the configuration once; changes made after loading take
effect on a later invocation.

Database exceptions during direct or configuration-driven `fill` are reported as
`Database fill failed:` with exit status 1 and URL credentials redacted, without a
Python traceback. For a missing SQLite `mode=rw` target, no file is created;
correct the target and retry. This diagnostic does not imply rollback of earlier
committed batches.

If any table reports generation errors, the command prints those errors and exits
with status 1. `count` reports rows actually committed; a later batch failure can
leave earlier commits. A snapshot retains a supplied transform script path and replay
runs that script again; the script itself is not embedded in the snapshot.

Replay matches saved table settings using SQLite's ASCII-only case-insensitive
name rules; non-ASCII names and PostgreSQL names remain distinct. Multiple saved
configurations matching the replay table are rejected before generation rather
than choosing one silently. Snapshots without matching table settings retain the
legacy defaults.

Snapshots also retain `--enrich`. Enriched replay reads the current table distribution,
not a frozen copy of the original rows. Older snapshots without this setting
retain the default (`false`).

`replay` reports missing, unreadable, or malformed snapshot files with exit status 2
before generation starts. Check the path, read permissions, and UTF-8 YAML syntax.
Snapshot metadata requires a nonblank string `table_name`, a positive integer
`count`, and an integer or null `seed` (which may be omitted). Boolean values are
not accepted as integers.

The optional AI plugin registers `ai-suggest`, `ai-analyze`, and `auto-heal` through
`sqlseed.cli_commands`. CLI does not require AI for its five base commands.

## Requirements

These metadata requirements apply to version 0.2.7 and its source candidates.
Use local Core and plugins together when developing from source.

- Python `>=3.10`
- `sqlseed>=0.2.5.dev0,<0.3`
- `click>=8.0`
- `rich>=13.0`

See the [user guide](https://sunbos.github.io/sqlseed/guide/),
[migration guide](https://sunbos.github.io/sqlseed/migration/), and
[package source](https://github.com/sunbos/sqlseed/tree/main/plugins/sqlseed-cli).

License: [AGPL-3.0-or-later](https://github.com/sunbos/sqlseed/blob/main/LICENSE).
The distribution includes the full LICENSE text.

