/
Ru5Kasper
/
Trackly
Обзор
Документация
Войти
/
Ru5Kasper
/
Trackly
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
backend/reset_db.py
70 строк
2 KB
DORANDKOR
feat(backend): create migrations, add support for user avatars
31 мар 2026, 07:30
31 мар 2026, 07:30
b6b9ba7
Код
Авторство
О чём код?
#!/usr/bin/env python3 """ Database reset script - drops all tables and reapplies migrations. WARNING: This will delete ALL data in your database! Usage: python reset_db.py """ import asyncio import sys import subprocess from sqlalchemy import text from app.database import engine async def drop_all_tables(): """Drop all tables from the database.""" print("Dropping all tables...") async with engine.begin() as conn: # Execute each statement separately (asyncpg doesn't support multiple commands) await conn.execute(text("DROP SCHEMA public CASCADE")) await conn.execute(text("CREATE SCHEMA public")) await conn.execute(text("GRANT ALL ON SCHEMA public TO public")) print("✓ All tables dropped") async def main(): """Main entry point.""" print("=" * 60) print("DATABASE RESET") print("=" * 60) print("\nWARNING: This will delete ALL data in your database!") print("\nCurrent database:", engine.url) response = input("\nAre you sure you want to continue? (yes/no): ") if response.lower() not in ["yes", "y"]: print("Aborted.") return 0 try: # Drop all tables await drop_all_tables() await engine.dispose() # Run migrations print("\nApplying migrations...") result = subprocess.run( ["uv", "run", "alembic", "upgrade", "head"], check=True, ) if result.returncode == 0: print("\n" + "=" * 60) print("✓ Database reset complete!") print("=" * 60) return 0 else: print("\n✗ Migration failed") return 1 except Exception as e: print(f"\n✗ Error: {e}") return 1 if __name__ == "__main__": sys.exit(asyncio.run(main()))