Migration for quotas added
This commit is contained in:
parent
0f423166f1
commit
0043abdbad
9
migrations/202311251700.py
Normal file
9
migrations/202311251700.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from mongodb_migrations.base import BaseMigration
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(BaseMigration):
|
||||||
|
def upgrade(self):
|
||||||
|
self.db.users.update_many({}, {"$set": {"quota": None}})
|
||||||
|
|
||||||
|
def downgrade(self):
|
||||||
|
self.db.test_collection.update_many({}, {"$unset": "quota"})
|
23
modules/migrator.py
Normal file
23
modules/migrator.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from typing import Any, Mapping
|
||||||
|
|
||||||
|
from mongodb_migrations.cli import MigrationManager
|
||||||
|
from mongodb_migrations.config import Configuration
|
||||||
|
|
||||||
|
from modules.utils import configGet
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_database() -> None:
|
||||||
|
"""Apply migrations from folder `migrations/` to the database"""
|
||||||
|
db_config: Mapping[str, Any] = configGet("database")
|
||||||
|
|
||||||
|
manager_config = Configuration(
|
||||||
|
{
|
||||||
|
"mongo_host": db_config["host"],
|
||||||
|
"mongo_port": db_config["port"],
|
||||||
|
"mongo_database": db_config["name"],
|
||||||
|
"mongo_username": db_config["user"],
|
||||||
|
"mongo_password": db_config["password"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
manager = MigrationManager(manager_config)
|
||||||
|
manager.run()
|
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from argparse import ArgumentParser
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -6,6 +7,7 @@ from fastapi.responses import FileResponse
|
|||||||
|
|
||||||
from modules.app import app
|
from modules.app import app
|
||||||
from modules.extensions_loader import dynamic_import_from_src
|
from modules.extensions_loader import dynamic_import_from_src
|
||||||
|
from modules.migrator import migrate_database
|
||||||
from modules.scheduler import scheduler
|
from modules.scheduler import scheduler
|
||||||
|
|
||||||
makedirs(Path("data/users"), exist_ok=True)
|
makedirs(Path("data/users"), exist_ok=True)
|
||||||
@ -27,3 +29,15 @@ dynamic_import_from_src("extensions", star_import=True)
|
|||||||
# =================================================================================
|
# =================================================================================
|
||||||
|
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
|
parser = ArgumentParser(
|
||||||
|
prog="PhotosAPI",
|
||||||
|
description="Small and simple API server for saving photos and videos.",
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument("--migrate", action="store_true")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.migrate:
|
||||||
|
migrate_database()
|
||||||
|
@ -2,6 +2,7 @@ aiofiles==23.2.1
|
|||||||
apscheduler~=3.10.1
|
apscheduler~=3.10.1
|
||||||
exif==1.6.0
|
exif==1.6.0
|
||||||
fastapi[all]==0.104.1
|
fastapi[all]==0.104.1
|
||||||
|
mongodb-migrations==1.3.0
|
||||||
opencv-python~=4.8.1.78
|
opencv-python~=4.8.1.78
|
||||||
passlib~=1.7.4
|
passlib~=1.7.4
|
||||||
pymongo>=4.3.3
|
pymongo>=4.3.3
|
||||||
|
Loading…
Reference in New Issue
Block a user