Metadata-Version: 2.4
Name: mezon
Version: 0.1.0
Summary: Constraint preservation verification for Django migrations, via Alloy 6
Author: Abduaziz Ziyodov
Author-email: Abduaziz Ziyodov <mail@ziyodov.uz>
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE.txt
Requires-Dist: returns[compatible-mypy]>=0.28.0
Requires-Dist: django>=5.2 ; extra == 'django'
Requires-Python: >=3.12
Provides-Extra: django
Description-Content-Type: text/markdown

<div align=center>
  <img src=".github/assets/logo.svg" alt="logo"><br>
  <span>
    Constraint preservation verification for Django database migrations, via Alloy
  </span><br>
  <img src="https://ziyodov.uz/badges/ai-free-dark.svg" alt="badge">
  <img src="https://github.com/AbduazizZiyodov/mezon/actions/workflows/ci.yml/badge.svg" alt="ci-badge">
</div>

## Requirements

- Mezon[^1] needs CPython +3.12, Java +11 on `PATH`
- Get `org.alloytools.alloy.dist.jar` from [there](https://github.com/AlloyTools/org.alloytools.alloy/releases/download/v6.2.0/org.alloytools.alloy.dist.jar) and point Mezon at it (it will search/choose in this order):

1. `--alloy-jar /....`
2. `MEZON_ALLOY_JAR=/....`
3. `~/.mezon/org.alloytools.alloy.dist.jar` - I prefer this one

> [!WARNING]
> You must install it in your own Python environment, it will select Django from there.

## Usage / Commands

(pasted from `--help`)

```bash
usage: mezon [-h] [--version] [--scope SCOPE] [--alloy-jar ALLOY_JAR] {verify,preserve,regress,audit} ...

Constraint preservation verification for Django migrations

positional arguments:
  {verify,preserve,regress,audit}
    verify              check the current schema is satisfiable
    preserve            check a migration preserves the schema's satisfiability
    regress             warn when a migration tightens a constraint, excluding valid rows
    audit               replay a project's migration history

options:
  -h, --help            show this help message and exit
  --version, -V         show program's version number and exit
  --scope SCOPE         override completeness threshold (1 row, 2 for pair runs)
  --alloy-jar ALLOY_JAR
                        path to org.alloytools.alloy.dist.jar
```

## Development

```bash
uv sync --all-groups
```

```bash
make chores
make test
```

## Back History

I took Database course(s) during Junior student year (bachelors) - the origin of this project ties back to that period where we had to do research project for semester on this subject.

Originally, intention was to verify whether given SQL satisfies ERD where ERD had complex/rich constructs & constraints (e.g. disjoint, union) which needed special handling in SQL world. With available knowledge that I had from theory(first order logic, relational algebra etc.) I was thinking to formalize this problem to achieve provable solution.

Among the all approaches that I had in my mind - *mapping all of those table/constraint(s) into Alloy (which has everything I need)* seemed reasonable - and we had many discussions around it. However, it was hard to achieve tangible results during one semester since its short - for the sake of the course we reframed the idea, and completed the project(no Alloy, FM here - but unfortunately, Mermaid involved).

Since then, I've been doing independent research on this project (Junior -> Senior -> now I'm graduated). Idea itself is re-shaped many times, and here we are. On top of checking model's static state(similar to original problem), I'm considering schema evolution operations too. To apply the findings, perform experiments - I chose Django. Static part was handled by ORM models & for schema evolution it provided migration framework of its own.

> [!IMPORTANT]
> This repository starts fresh since earlier iterations accumulated materials I could not redistribute, so I moved the project here rather than carry that all history (force pushes won't help too).

During Database course, my professor was "trigger" for this project. I hope it will continue.

[^1]: Mezon is an Uzbek word for a criterion or measure
