-
Notifications
You must be signed in to change notification settings - Fork 75
/
__init__.py
44 lines (38 loc) · 1.18 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import log
from config import Config
from .main_db import MainDb
from .main_db import DbPersist
from .media_db import MediaDb
from alembic.config import Config as AlembicConfig
from alembic.command import upgrade as alembic_upgrade
def init_db():
"""
初始化数据库
"""
log.console('开始初始化数据库...')
MediaDb().init_db()
MainDb().init_db()
log.console('数据库初始化完成')
def init_data():
"""
初始化数据
"""
log.console('开始初始化数据...')
MainDb().init_data()
log.console('数据初始化完成')
def update_db():
"""
更新数据库
"""
db_location = os.path.normpath(os.path.join(Config().get_config_path(), 'user.db'))
script_location = os.path.normpath(os.path.join(Config().get_root_path(), 'scripts'))
log.console('开始更新数据库...')
try:
alembic_cfg = AlembicConfig()
alembic_cfg.set_main_option('script_location', script_location)
alembic_cfg.set_main_option('sqlalchemy.url', f"sqlite:///{db_location}")
alembic_upgrade(alembic_cfg, 'head')
log.console('数据库更新完成')
except Exception as e:
pass