diff --git a/alembic.ini b/alembic.ini index be00fc0b..921aaf17 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,9 +35,6 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = sqlite:///mautrix-telegram.db - - # Logging configuration [loggers] keys = root,sqlalchemy,alembic diff --git a/alembic/env.py b/alembic/env.py index ea7af9f1..58ebcf51 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,3 @@ -from __future__ import with_statement from alembic import context from sqlalchemy import engine_from_config, pool from logging.config import fileConfig @@ -8,12 +7,19 @@ sys.path.insert(0, dirname(dirname(abspath(__file__)))) from mautrix_telegram.base import Base +from mautrix_telegram.config import Config import mautrix_telegram.db # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config +mxtg_config_path = context.get_x_argument(as_dictionary=True).get("config", "config.yaml") +mxtg_config = Config(mxtg_config_path, None, None) +mxtg_config.load() +config.set_main_option("sqlalchemy.url", + mxtg_config.get("appservice.database", "sqlite:///mautrix-telegram.db")) + # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) diff --git a/docker/root/etc/s6.d/mautrix-telegram/run b/docker/root/etc/s6.d/mautrix-telegram/run index c82315a1..41eb26aa 100755 --- a/docker/root/etc/s6.d/mautrix-telegram/run +++ b/docker/root/etc/s6.d/mautrix-telegram/run @@ -10,12 +10,11 @@ function fixperms { cd /opt/mautrixtelegram export FFMPEG_BINARY=/usr/bin/ffmpeg -# Replace database path in alembic.ini -sed -i "s#sqlite:///mautrix-telegram.db#sqlite:////data/mautrix-telegram.db#" alembic.ini +# Replace database path in config. sed -i "s#sqlite:///mautrix-telegram.db#sqlite:////data/mautrix-telegram.db#" /data/config.yaml # Check that database is in the right state -alembic upgrade head +alembic -x config=/data/config.yaml upgrade head if [[ ! -f /data/config.yaml ]]; then cp example-config.yaml /data/config.yaml diff --git a/mautrix_telegram/__main__.py b/mautrix_telegram/__main__.py index 71710ef0..b8f29d58 100644 --- a/mautrix_telegram/__main__.py +++ b/mautrix_telegram/__main__.py @@ -26,7 +26,7 @@ from mautrix_appservice import AppService from .base import Base -from .config import Config, DictWithRecursion +from .config import Config from .matrix import MatrixHandler from .db import init as init_db