Metadata-Version: 2.4
Name: minimi-para
Version: 0.2.1
Summary: A mini migration tool
Author-email: Petr Jindra <el.mordo@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/elmordo/minimi
Project-URL: Repository, https://github.com/elmordo/minimi
Keywords: migrations,sqlalchemy,database
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: AUTHORS
Requires-Dist: sqlalchemy<3.0,>=2.0.52
Requires-Dist: sa-values<0.3,>=0.2.0
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: dev
Requires-Dist: sa-values[test]; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

**MINI**mal **MI**gration library tool for managing database migrations in small projects where
a full-featured migration tool would be overkill.

Why the "_para_" suffix? The original name of the library `minimi` was rejected by the pypi.org because
it is too similar to another library. Also, the Minimi Para is compatct version of the original Minimi :-)

```

                                     ====
             __@----------------\     \
||=========||====             ===\_____\___________        // //
||         ||====                                  |======|=| ALTER TABLE users DROP COLUMN email
||=========||---_____======------------------------|=|     \\ \\
               /   /  \\ /    \____________|      ||
              /   /------                         ||
             /___/                                ||
                                                  ||
                                                 ====
```

# Quick start

Create a migration module in your source directory

```
src
  +- mylib
    +- migrations
    |  +- __init__.py          <- list of migration modules
    |  +- m01_db_init.py       <- first revision
    |  +- m02_new_table.py     <- second revision
    +- other module
    +- main.py
```

```python
# __init__.py

from . import m01_db_init, m02_new_table

MIGRATIONS = [
    m01_db_init,
    m02_new_table,
]
```

```python
# m01_db_init.py

# the UP migration only
MIGRATIONS = """
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT NOT NULL UNIQUE
);
"""
```

```python
# m02_new_table.py

# the UP and DOWN migrations as tuple of two strings
MIGRATIONS = """
CREATE TABLE IF NOT EXISTS user_comments (
    id INTEGER PRIMARY KEY,
    user_id INTEGER NOT NULL
        REFERENCES users(id),
    subjects TEXT NOT NULL,
    message TEXT NOT NULL
);
""", """
DROP TABLE IF EXISTS user_comments;
"""
```

```python
# main.py

from minimi import Minimi
from sqlalchemy import create_engine
from sa_values import setup_sa_values

import mylib.migrations as migrations


def main():
    # initialize the sa_values first
    conn = create_engine("sqlite:///:memory:").connect()
    setup_sa_values(conn)
    # run the migrations
    Minimi(conn, migrations).apply()


if __name__ == "__main__":
    main()
```

# Usage

The `__init__.py` file contains a list of migration modules in the `MIGRATIONS` global variable with list of migration
modules.

Each migration module must contain the `MIGRATION` global variable with the migration.

# Buy me a ~~coffee~~ beer

If you like this library, or you want to support its development, support me by one
cold [beer](https://www.buymeacoffee.com/elmordo). The beer is tasty and full of vitamins :-)
