3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,4 +4,5 @@ test.php
|
|||||||
**/__pycache__
|
**/__pycache__
|
||||||
database.db*
|
database.db*
|
||||||
.idea
|
.idea
|
||||||
db_fixtures
|
db_fixtures
|
||||||
|
backups
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "meal-manager"
|
name = "meal-manager"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = "Add your description here"
|
description = "Add your description here"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = "~=3.13.0"
|
requires-python = "~=3.13.0"
|
||||||
@@ -25,7 +25,7 @@ dev = [
|
|||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
apply-subscriptions = "meal_manager.scripts:apply_subscriptions_cli"
|
apply-subscriptions = "meal_manager.scripts:apply_subscriptions_cli"
|
||||||
|
meal-manager-nightly = "meal_manager.scripts:run_nightly_tasks"
|
||||||
|
|
||||||
[tool.isort]
|
[tool.isort]
|
||||||
profile = "black"
|
profile = "black"
|
||||||
|
|||||||
@@ -1,13 +1,36 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from sqlalchemy import Date, cast, func, select
|
from sqlalchemy import func, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from meal_manager.main import engine
|
from meal_manager.main import engine, sqlite_file_name
|
||||||
from meal_manager.models import Event, Registration, Subscription
|
from meal_manager.models import Event, Registration, Subscription
|
||||||
|
|
||||||
|
|
||||||
|
def backup_db():
|
||||||
|
backup_dir = Path(os.environ.get("MEAL_MANAGER_BACKUP_DIR", None))
|
||||||
|
shutil.copy2(
|
||||||
|
sqlite_file_name,
|
||||||
|
backup_dir / f"{sqlite_file_name}.{datetime.datetime.now().isoformat()}",
|
||||||
|
)
|
||||||
|
# TODO: Delete old backups
|
||||||
|
|
||||||
|
|
||||||
|
def run_nightly_tasks():
|
||||||
|
print("Applying Subscriptions")
|
||||||
|
with Session(engine) as session:
|
||||||
|
apply_subscriptions(session)
|
||||||
|
|
||||||
|
print("Running db backup")
|
||||||
|
backup_db()
|
||||||
|
|
||||||
|
print("Done running nightly tasks.")
|
||||||
|
|
||||||
|
|
||||||
def apply_subscriptions(session: Session, event: Event = None, dry_run: bool = False):
|
def apply_subscriptions(session: Session, event: Event = None, dry_run: bool = False):
|
||||||
|
|
||||||
subscriptions = session.scalars(select(Subscription)).all()
|
subscriptions = session.scalars(select(Subscription)).all()
|
||||||
|
|||||||
Reference in New Issue
Block a user