/
Ru5Kasper
/
Trackly
Обзор
Документация
Войти
/
Ru5Kasper
/
Trackly
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
backend/migrate.py
71 строка
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 migration management script. Usage: python migrate.py upgrade # Apply all pending migrations python migrate.py downgrade # Revert last migration python migrate.py current # Show current migration version python migrate.py history # Show migration history python migrate.py stamp # Mark database at specific version without running migrations """ import sys import subprocess def run_alembic(command: str): """Run alembic command using uv.""" try: result = subprocess.run( ["uv", "run", "alembic"] + command.split(), check=True, capture_output=False, ) return result.returncode except subprocess.CalledProcessError as e: print(f"Error running alembic command: {e}") return e.returncode except FileNotFoundError: print("Error: 'uv' command not found. Make sure uv is installed.") return 1 def main(): """Main entry point.""" if len(sys.argv) < 2: print(__doc__) return 1 command = sys.argv[1].lower() if command == "upgrade": print("Applying all pending migrations...") return run_alembic("upgrade head") elif command == "downgrade": print("Reverting last migration...") return run_alembic("downgrade -1") elif command == "current": print("Current migration version:") return run_alembic("current") elif command == "history": print("Migration history:") return run_alembic("history") elif command == "stamp": revision = sys.argv[2] if len(sys.argv) > 2 else "head" print(f"Stamping database at revision: {revision}") print("Note: This marks the database without running migrations.") return run_alembic(f"stamp {revision}") else: print(f"Unknown command: {command}") print(__doc__) return 1 if __name__ == "__main__": sys.exit(main())