feat: export Markdown notes (ARQ/Redis) + backup/restore BDD — v0.5.2
- Volume data/ (bind mount ./data) remplace le volume uploads nommé
data/notes/ → .md auto-générés, data/uploads/ → médias, data/backup/ → dumps
- Service Redis (redis:7-alpine) + worker ARQ (backend-worker)
- notes_markdown.py : frontmatter YAML + contenu + pièces jointes (liens relatifs)
Nom : YYYY-MM-DD_slug-titre_shortid.md, rotation si titre modifié
- api/notes.py : publie export_note_markdown / remove_note_markdown sur Redis
après chaque create / update / delete / add_attachment / delete_attachment
- api/admin.py : POST /backup, GET /backups, POST /restore/{filename} (pg_dump/pg_restore)
- Backend Dockerfile : postgresql-client ; requirements : arq==0.26.1
- ConfigPage : section "Base de données" avec sauvegarde + liste + restauration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from arq.connections import RedisSettings
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import AsyncSessionLocal
|
||||
from app.models.notes import NoteItem
|
||||
from app.services.notes_markdown import delete_note_markdown, save_note_markdown
|
||||
|
||||
|
||||
async def export_note_markdown(ctx: dict, note_id: str) -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
stmt = (
|
||||
select(NoteItem)
|
||||
.where(NoteItem.id == note_id)
|
||||
.options(selectinload(NoteItem.attachments))
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
note = result.scalar_one_or_none()
|
||||
if note:
|
||||
save_note_markdown(note)
|
||||
|
||||
|
||||
async def remove_note_markdown(ctx: dict, note_id: str) -> None:
|
||||
delete_note_markdown(note_id)
|
||||
|
||||
|
||||
class WorkerSettings:
|
||||
functions = [export_note_markdown, remove_note_markdown]
|
||||
redis_settings = RedisSettings.from_dsn(settings.redis_url)
|
||||
Reference in New Issue
Block a user