Databases (ixmp4.db)

Module contents

This module is responsible for everything database related. Interfacing, migrating and more is all done here.

It uses sqlalchemy and alembic for database management.

Migrations

There is a development database at run/db.sqlite which is used for generating migrations, nothing else. It can be manipulated with alembic directly using these commands:

# run all migrations until the current state is reached
alembic upgrade head

# run one migration forward
alembic upgrade +1

# run one migration backward
alembic downgrade -1

# autogenerate new migration (please choose a descriptive change message)
alembic revision -m "<message>" --autogenerate

You will have to run all migrations before being able to create new ones in the development database. Be sure to run ruff on newly created migrations before committing them!

Subpackages

Submodules

ixmp4.db.filters module

ixmp4.db.filters.BaseFilter

alias of BaseFilter

class ixmp4.db.filters.FilterMeta(name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any)

Bases: ModelMetaclass

classmethod build_lookups(field_type: type) dict[str, tuple[type, Callable[[...], Any]]]
classmethod expand_lookups(name: str, lookups: dict[str, tuple[type, Callable[[...], Any]]], namespace: dict[str, Any], base_field_alias: str | None = None) None
classmethod process_field(namespace: dict[str, Any], field_name: str, field_type: type) None
class ixmp4.db.filters.Float(x=0, /)

Bases: float

An explicit proxy type for float.

class ixmp4.db.filters.Id

Bases: int

A no-op type for a reduced set of Integer lookups.

class ixmp4.db.filters.Integer

Bases: int

An explicit proxy type for int.

class ixmp4.db.filters.String

Bases: str

An explicit proxy type for str.

ixmp4.db.filters.escape_wildcard(v: str) str
ixmp4.db.filters.expand_simple_filter(value: ExpandType | dict[str, ExpandType]) dict[str, ExpandType]
ixmp4.db.filters.get_filter_func_name(n: str) str
ixmp4.db.filters.ilike(c: Column[str], v: str) BinaryExpression[bool]
ixmp4.db.filters.in_(c: Column[in_Type], v: Iterable[in_Type] | BindParameter[in_Type]) BinaryExpression[bool]
ixmp4.db.filters.like(c: Column[str], v: str) BinaryExpression[bool]
ixmp4.db.filters.notilike(c: Column[str], v: str) BinaryExpression[bool]
ixmp4.db.filters.notlike(c: Column[str], v: str) BinaryExpression[bool]