hydromodpy.core.migrations.runner#

Alembic-like migration runner generic over DuckDB databases.

The runner discovers <NNNN>_<slug>.sql scripts under versions_dir, records each application in schema_migrations and keeps one row of _schema_version per component in sync. It is idempotent: rerunning ensure_schema() on an up-to-date database applies nothing and only verifies checksum integrity.

The same runner serves multiple components by parametrizing component (e.g. "catalog" for project catalogs, "index" for the machine-wide global index).

Functions

apply_migration(connection, migration, *[, ...])

Apply one migration in a transaction and record it for component.

apply_migrations(db_path, migrations_dir, *)

Open db_path, apply pending migrations, return the new version.

current_version(connection, *[, component])

Return the highest applied version for component, 0 if none.

discover_migrations(versions_dir)

Return migrations sorted by version, rejecting gaps and duplicates.

ensure_schema(connection, *, versions_dir[, ...])

Bring component up to the highest available version.

list_migrations(versions_dir)

Public alias for discover_migrations().

target_version(versions_dir)

Return the highest migration version present on disk.