Coverage for slidge/migration.py: 57%
30 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 08:17 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 08:17 +0000
1import logging
2import shutil
3import sys
4from pathlib import Path
6from alembic import command
7from alembic.config import Config
8from slixmpp import JID
10from .core import config
11from .db.meta import get_engine
12from .db.models import GatewayUser
13from .db.store import SlidgeStore
16def remove_avatar_cache_v1() -> None:
17 old_dir = config.HOME_DIR / "slidge_avatars"
18 if old_dir.exists():
19 log.info("Avatar cache dir v1 found, clearing it.")
20 shutil.rmtree(old_dir)
23def get_alembic_cfg() -> Config:
24 alembic_cfg = Config()
25 alembic_cfg.set_section_option(
26 "alembic",
27 "script_location",
28 str(Path(__file__).parent / "db" / "alembic"),
29 )
30 return alembic_cfg
33def migrate() -> None:
34 remove_avatar_cache_v1()
35 command.upgrade(get_alembic_cfg(), "head")
38def main() -> None:
39 """
40 Updates the (dev) database in ./dev/slidge.sqlite and generates a revision
42 Usage: python -m slidge.migration "Revision message blah blah blah"
43 """
44 alembic_cfg = get_alembic_cfg()
45 command.upgrade(alembic_cfg, "head")
46 command.revision(alembic_cfg, sys.argv[1], autogenerate=True)
49log = logging.getLogger(__name__)
51if __name__ == "__main__":
52 main()