From b4e2d747cc9c13a526eed919b89e66d4cb57abb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylicki?= Date: Fri, 10 Apr 2020 07:17:23 +0200 Subject: [PATCH] Fix running alembic from installed package (#218) --- MANIFEST.in | 1 + rfhub2/db/migrate.py | 4 +++- rfhub2/version.py | 2 +- setup.py | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 0ce9b5c7..eddd3ae8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include README.md +include rfhub2/alembic.ini recursive-include rfhub2/static * recursive-include rfhub2/templates * recursive-exclude rfhub2 *~ #*# \ No newline at end of file diff --git a/rfhub2/db/migrate.py b/rfhub2/db/migrate.py index b276a6a3..235a2cab 100644 --- a/rfhub2/db/migrate.py +++ b/rfhub2/db/migrate.py @@ -1,6 +1,7 @@ from alembic.config import Config from alembic.runtime.migration import MigrationContext from alembic import command +from pathlib import Path from sqlalchemy.engine import Connection, Engine from sqlalchemy.engine.reflection import Inspector @@ -18,7 +19,8 @@ def has_revision(connection: Connection) -> bool: def migrate_db(engine: Engine) -> None: - alembic_cfg = Config("rfhub2/alembic.ini") + config_path = Path(__file__).resolve().parent.parent / "alembic.ini" + alembic_cfg = Config(config_path) with engine.begin() as connection: # check if database has not been migrated yet with alembic if has_tables(connection) and not has_revision(connection): diff --git a/rfhub2/version.py b/rfhub2/version.py index b3849f7d..d2687b77 100644 --- a/rfhub2/version.py +++ b/rfhub2/version.py @@ -1 +1 @@ -version = "0.17" +version = "0.18" diff --git a/setup.py b/setup.py index af4f7484..26ba26b0 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,8 @@ ], packages=[ 'rfhub2', + 'rfhub2.alembic', + 'rfhub2.alembic.versions', 'rfhub2.api', 'rfhub2.api.endpoints', 'rfhub2.api.middleware',