Skip to content

Commit

Permalink
Read database path from config in alembic env.py
Browse files Browse the repository at this point in the history
Slightly related to #135
  • Loading branch information
tulir committed May 29, 2018
1 parent e961e0b commit 6ef3159
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 0 additions & 3 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions docker/root/etc/s6.d/mautrix-telegram/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mautrix_telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ef3159

Please sign in to comment.