Files
ai_agent/backend/app/commands/cleanup.py
T
furyhawk 8351e73d39 feat: add Zustand stores for conversation, file preview, sidebar, theme, and knowledge base selection
- Implemented `conversation-store` for managing conversations and messages.
- Created `file-preview-store` to handle file preview state.
- Added `sidebar-store` for sidebar visibility management.
- Developed `theme-store` for theme persistence and management.
- Introduced `kb-selection-store` for managing active knowledge base selections with persistence.

chore: define API and chat types

- Added types for API responses, authentication, chat messages, conversations, and projects.
- Defined interfaces for various entities including users, sessions, and message ratings.

build: configure TypeScript and testing setup

- Set up `tsconfig.json` for TypeScript configuration.
- Created `vitest.config.ts` for testing configuration with Vitest.
- Added `vitest.setup.ts` for global test setup including mocks for Next.js router and media queries.
- Configured Vercel deployment settings in `vercel.json`.
2026-06-11 16:54:43 +08:00

46 lines
1.3 KiB
Python

"""
Cleanup old or stale data from the database.
This command is useful for maintenance tasks.
"""
import asyncio
from datetime import UTC, datetime, timedelta
import click
from app.commands import command, info, success, warning
@command("cleanup", help="Clean up old data from the database")
@click.option("--days", "-d", default=90, type=int, help="Delete records older than N days")
@click.option("--dry-run", is_flag=True, help="Show what would be deleted without making changes")
@click.option("--force", "-f", is_flag=True, help="Skip confirmation prompt")
def cleanup(days: int, dry_run: bool, force: bool) -> None:
"""
Remove old records from the database.
Example:
project cmd cleanup --days 90
project cmd cleanup --days 30 --dry-run
project cmd cleanup --days 7 --force
"""
cutoff_date = datetime.now(UTC) - timedelta(days=days)
if dry_run:
info(f"[DRY RUN] Would delete records older than {cutoff_date}")
return
if not force and not click.confirm(
f"Delete all records older than {days} days ({cutoff_date})?"
):
warning("Aborted.")
return
async def _cleanup() -> None:
info(f"Cleaning up records older than {cutoff_date}...")
total_deleted = 0
success(f"Done. Total deleted: {total_deleted} rows.")
asyncio.run(_cleanup())