move aerich conf to storage.db
This commit is contained in:
parent
9080f26e1c
commit
14bd3afa5b
|
@ -1,5 +1,4 @@
|
|||
[aerich]
|
||||
tortoise_orm = mobilizon_reshare.aerich_conf.database.TORTOISE_ORM
|
||||
tortoise_orm = mobilizon_reshare.storage.db.TORTOISE_ORM
|
||||
location = ./migrations
|
||||
src_folder = ./.
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
"""tortoise orm conf for aerich"""
|
||||
from pathlib import Path
|
||||
from mobilizon_reshare.config.config import get_settings
|
||||
|
||||
CONF_FILE = "mobilizon_reshare/settings.toml"
|
||||
|
||||
SETTINGS = get_settings(CONF_FILE)
|
||||
db_path = Path(SETTINGS.db_path)
|
||||
print(db_path)
|
||||
|
||||
db_url = f"sqlite:///{db_path}"
|
||||
|
||||
TORTOISE_ORM = {
|
||||
"connections": {"default": db_url},
|
||||
"apps": {
|
||||
"models": {
|
||||
"models": ["mobilizon_reshare.models.event",
|
||||
"mobilizon_reshare.models.notification",
|
||||
"mobilizon_reshare.models.publication",
|
||||
"mobilizon_reshare.models.publisher", "aerich.models"],
|
||||
"default_connection": "default",
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,16 +1,41 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from tortoise import Tortoise
|
||||
|
||||
from aerich import Command
|
||||
from mobilizon_reshare.config.publishers import publisher_names
|
||||
from mobilizon_reshare.storage.query.write import update_publishers
|
||||
from aerich import Command
|
||||
from mobilizon_reshare.aerich_conf.database import TORTOISE_ORM
|
||||
|
||||
from mobilizon_reshare.config.config import get_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_db_url():
|
||||
"""gets db url from settings
|
||||
|
||||
Returns:
|
||||
str : db url
|
||||
"""
|
||||
settings = get_settings()
|
||||
db_path = Path(settings.db_path)
|
||||
db_url = f"sqlite:///{db_path}"
|
||||
return db_url
|
||||
|
||||
|
||||
TORTOISE_ORM = {
|
||||
"connections": {"default": get_db_url()},
|
||||
"apps": {
|
||||
"models": {
|
||||
"models": ["mobilizon_reshare.models.event",
|
||||
"mobilizon_reshare.models.notification",
|
||||
"mobilizon_reshare.models.publication",
|
||||
"mobilizon_reshare.models.publisher", "aerich.models"],
|
||||
"default_connection": "default",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class MoReDB:
|
||||
def __init__(self, path: Path):
|
||||
self.path = path
|
||||
|
@ -30,7 +55,7 @@ class MoReDB:
|
|||
async def setup(self):
|
||||
await self._implement_db_changes()
|
||||
await Tortoise.init(
|
||||
db_url=f"sqlite:///{self.path}",
|
||||
db_url=get_db_url(),
|
||||
modules={
|
||||
"models": [
|
||||
"mobilizon_reshare.models.event",
|
||||
|
|
Loading…
Reference in New Issue