diff --git a/README.md b/README.md index 58bfcd4..36c53e0 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,6 @@ In case of database structure upgrade, developers must follow these steps: For details about the alembic migration tool, see the [Alembic tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html). - ## License ``` diff --git a/alembic/README b/alembic/README index 98e4f9c..2500aa1 100644 --- a/alembic/README +++ b/alembic/README @@ -1 +1 @@ -Generic single-database configuration. \ No newline at end of file +Generic single-database configuration. diff --git a/alembic/env.py b/alembic/env.py index bb9d102..ebadbee 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -52,14 +52,14 @@ def run_migrations_online() -> None: alembic.context.configure( connection=connection, target_metadata=cacholote.database.Base.metadata, - version_table='alembic_version_cacholote' + version_table="alembic_version_cacholote", ) with alembic.context.begin_transaction(): alembic.context.run_migrations() -if context.is_offline_mode(): +if alembic.context.is_offline_mode(): run_migrations_offline() else: run_migrations_online() diff --git a/alembic/versions/a38663d192e5_add_created_at_and_rename_timestamp_.py b/alembic/versions/a38663d192e5_add_created_at_and_rename_timestamp_.py index cbaa171..01cf0d5 100644 --- a/alembic/versions/a38663d192e5_add_created_at_and_rename_timestamp_.py +++ b/alembic/versions/a38663d192e5_add_created_at_and_rename_timestamp_.py @@ -1,20 +1,20 @@ """add created_at and rename timestamp column. Revision ID: a38663d192e5 -Revises: +Revises: Create Date: 2024-07-24 15:53:43.989464 """ -import datetime + from typing import Sequence, Union import sqlalchemy as sa -from alembic import op import cacholote +from alembic import op # revision identifiers, used by Alembic. -revision: str = 'a38663d192e5' +revision: str = "a38663d192e5" down_revision: Union[str, None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None diff --git a/cacholote/database.py b/cacholote/database.py index 8456a3c..0f660f2 100644 --- a/cacholote/database.py +++ b/cacholote/database.py @@ -18,11 +18,16 @@ import datetime import functools import json +import os import warnings from typing import Any import sqlalchemy as sa import sqlalchemy.orm +import sqlalchemy_utils + +import alembic.command +import alembic.config from . import utils @@ -116,7 +121,6 @@ def cached_sessionmaker(url: str, **kwargs: Any) -> sa.orm.sessionmaker[sa.orm.S return _cached_sessionmaker(url, **_encode_kwargs(**kwargs)) - def init_database(connection_string: str, force: bool = False) -> sa.engine.Engine: """ Make sure the db located at URI `connection_string` exists updated and return the engine object. diff --git a/ci/environment-ci.yml b/ci/environment-ci.yml index 1f02127..82516c3 100644 --- a/ci/environment-ci.yml +++ b/ci/environment-ci.yml @@ -33,3 +33,4 @@ dependencies: - zarr - pip: - pytest-structlog + - types-sqlalchemy-utils diff --git a/environment.yml b/environment.yml index af0fda8..dd71ebd 100644 --- a/environment.yml +++ b/environment.yml @@ -13,4 +13,5 @@ dependencies: - pydantic - pydantic-settings - sqlalchemy>=2.0.9 +- sqlalchemy-utils - structlog diff --git a/pyproject.toml b/pyproject.toml index de6626a..c8f3570 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ dependencies = [ "pydantic", "pydantic-settings", "sqlalchemy>=2.0.9", + "sqlalchemy_utils", "structlog" ] description = "Efficiently cache calls to functions"