Metadata-Version: 2.4
Name: tesserakit-sql
Version: 0.4.0
Summary: SQL job pack for Tessera: lint SQL files/migrations into a statement and table catalog.
Project-URL: Homepage, https://github.com/ShaileshRawat1403/tessera
Project-URL: Repository, https://github.com/ShaileshRawat1403/tessera
Project-URL: Issues, https://github.com/ShaileshRawat1403/tessera/issues
Author: Shailesh Rawat
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: pydantic>=2.7
Requires-Dist: rich>=13.7
Requires-Dist: tesserakit-core>=0.1.0
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# tesserakit-sql

Lint SQL files and migrations into a statement and table catalog.

`tessera-sql` parses `.sql` files with lightweight heuristics (no database connection, no execution), builds a catalog of statements and declared tables, and flags high-signal migration-safety issues.

## Lint SQL

```bash
tessera sql lint --input migrations/ --output ./out/sql_pack
tessera sql lint --input schema.sql --output ./out/sql_pack
```

Artifacts written:

```text
statements.jsonl         one SqlStatement per parsed statement (kind, target, flags)
tables.jsonl             one SqlTable per CREATE TABLE (columns, primary-key flag)
index.md                 statement catalog
validation_report.md     safety findings
coverage_report.md       statement-kind distribution
tables.md                table catalog with columns and PK status
```

## Lint rules

Query safety:

- `delete_without_where` (error) — `DELETE` with no `WHERE` removes every row
- `update_without_where` (warning) — `UPDATE` with no `WHERE` writes every row
- `select_star` (info) — `SELECT *` couples the query to column shape

Migration safety (the costly, easy-to-miss class):

- `add_not_null_without_default` (error) — `ALTER TABLE ... ADD COLUMN ... NOT NULL` with no `DEFAULT` rewrites the table and fails on existing rows
- `truncate_table` (warning) — `TRUNCATE` wipes all rows and is often non-transactional / irreversible
- `drop_column` (warning) — dropping a column is destructive and irreversible
- `rename_breaks_compatibility` (warning) — `RENAME` breaks code referencing the old name; prefer add-new + backfill + drop-old
- `drop_without_if_exists` (warning) — `DROP` without `IF EXISTS` fails if the object is absent
- `create_table_without_if_not_exists` (info) — non-idempotent if the migration re-runs

Schema:

- `table_without_primary_key` (warning) — a `CREATE TABLE` declares no `PRIMARY KEY`
- `no_statements` — nothing parsed

## Limitations (v0.1)

Parsing is heuristic: comments are stripped, statements are split on top-level
semicolons (quote-aware), and classification is keyword/regex based. It is tuned
for migration and schema files, not for validating arbitrary vendor SQL dialects.
