Metadata-Version: 2.3
Name: pinta-db
Version: 0.2.0
Summary: Database component of the elevation production system
Requires-Dist: geoalchemy2>=0.18.4
Requires-Dist: sqlmodel>=0.0.37
Requires-Dist: pinta-lib
Requires-Dist: alembic>=1.18.4 ; extra == 'migrations'
Requires-Dist: dotenv>=0.9.9 ; extra == 'migrations'
Requires-Dist: psycopg[binary]>=3.3.3 ; extra == 'migrations'
Requires-Dist: alembic-utils>=0.8.8 ; extra == 'migrations'
Requires-Dist: psycopg[binary]>=3.3.3 ; extra == 'psycopg'
Requires-Dist: geoalchemy2[shapely] ; extra == 'shapely'
Requires-Dist: numpy>=2 ; extra == 'shapely'
Requires-Python: >=3.12, <3.14
Project-URL: Homepage, https://github.com/nlsfi/pinta
Project-URL: Repository, https://github.com/nlsfi/pinta
Project-URL: Changelog, https://github.com/nlsfi/pinta/blob/main/db/processing/CHANGELOG.md/
Provides-Extra: migrations
Provides-Extra: psycopg
Provides-Extra: shapely
Description-Content-Type: text/markdown

# Database component

Database-specific documentation:

* Primary DB: [schema documentation](./docs/primary_db/README.md) and [role/privilege documentation](./docs/primary_db/roles.md)
* Job DB: [schema documentation](./docs/job_db/README.md) and [role/privilege documentation](./docs/job_db/roles.md)

## Installation

Install all dependencies and extras with `uv sync --all-extras`.

## Creating migrations

### Manual

Manual migrations have to be made for example when creating new roles or schemas.
To generate autogenerated migration, run the following command with the suitable path to alembic.ini file:

```bash
uv run alembic -c src/pinta_db_migrations/<job|primary>/alembic.ini revision -m "Migration description" --rev-id="migration_id"
```

Then modify this migration file to include all necessary changes.

### Autogenerated

To create migrations modify database models first.
Make sure to have the models imported in [env.py](./src/pinta_db_migrations/primary/env.py)
by adding them into [models.all](./src/pinta_db/models/all.py) module.

After models for the target database have been modified, run the following command with the suitable path to alembic.ini file:

```bash
uv run alembic -c src/pinta_db_migrations/<job|primary>/alembic.ini revision --autogenerate -m "Migration description" --rev-id="migration_id"
```

This command will generate a new migration file for the target database based on the changes made to the models.

Check the created migration file and make sure it is correct and remove Alembic autogenerated
comments from the top and bottom of the functions. Remember to commit it in the repository.

## Running migrations

To run migrations and sync users in development, in the root of the project run:

```bash
make db-migrate-all
```

or just run migrations in this directory:

```bash
uv run alembic -c src/pinta_db_migrations/<job|primary>/alembic.ini upgrade head
```
