Files
orion/Makefile
2025-09-21 13:00:10 +02:00

457 lines
15 KiB
Makefile

# Comprehensive Makefile for LetzShop API (Windows Compatible)
.PHONY: install install-test install-dev install-docs install-all dev test test-unit test-integration test-coverage test-fast test-slow test-auth test-products test-stock lint format check docker-build docker-up docker-down migrate clean check-tools setup setup-test docs docs-serve docs-build docs-deploy docs-clean help
# Check if required tools are installed (Windows compatible)
check-tools:
@where black >nul 2>&1 || (echo black is required but not installed. Run 'make install-dev' first. && exit 1)
@where isort >nul 2>&1 || (echo isort is required but not installed. Run 'make install-dev' first. && exit 1)
@where flake8 >nul 2>&1 || (echo flake8 is required but not installed. Run 'make install-dev' first. && exit 1)
@where mypy >nul 2>&1 || (echo mypy is required but not installed. Run 'make install-dev' first. && exit 1)
check-docs-tools:
@where mkdocs >nul 2>&1 || (echo mkdocs is required but not installed. Run 'make install-docs' first. && exit 1)
# Development setup
install:
pip install -r requirements.txt
install-test:
pip install -r tests/requirements-test.txt
install-dev:
pip install -r requirements.txt
pip install -r tests/requirements-test.txt
pip install -r requirements-dev.txt
install-docs:
pip install -r requirements-docs.txt
install-all: install install-test install-dev install-docs
# Development servers
dev:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Safe development startup (checks migrations first)
dev-safe: migrate-check
@echo 🔍 Migration check passed, starting development server...
uvicorn main:app --reload --host 0.0.0.0 --port 8000
dev-with-docs:
@echo Starting API server and documentation server...
@start /B uvicorn main:app --reload --host 0.0.0.0 --port 8000
@timeout /t 3 >nul
@mkdocs serve --dev-addr=0.0.0.0:8001
# Combined development environment
dev-full: dev-with-docs
@echo Development environment ready!
@echo API server: http://localhost:8000
@echo API docs: http://localhost:8000/docs
@echo Documentation: http://localhost:8001
# Full development setup with fresh database
dev-fresh: setup-fresh dev-full
# Documentation commands
docs: docs-serve
docs-serve:
@echo Starting MkDocs development server...
mkdocs serve --dev-addr=0.0.0.0:8001
docs-build:
@echo Building documentation site...
mkdocs build --clean --strict
docs-build-quiet:
@echo Building documentation (quiet)...
mkdocs build --clean --quiet
docs-deploy:
@echo Deploying documentation to GitHub Pages...
mkdocs gh-deploy --clean
docs-deploy-force:
@echo Force deploying documentation to GitHub Pages...
mkdocs gh-deploy --clean --force
docs-update:
@echo Updating documentation with API information...
python scripts/update_docs.py
docs-clean:
@echo Cleaning documentation build files...
@if exist site rmdir /s /q site
@echo Documentation build files cleaned!
docs-check:
@echo Checking documentation for issues...
mkdocs build --strict --verbose
docs-help:
mkdocs --help
# Testing commands
test:
pytest tests/ -v
test-unit:
pytest tests/ -v -m unit
test-integration:
pytest tests/ -v -m integration
test-coverage:
pytest tests/ --cov=app --cov=models --cov=utils --cov=middleware --cov-report=html --cov-report=term-missing
test-fast:
pytest tests/ -v -m "not slow"
test-slow:
pytest tests/ -v -m slow
# Specific test files
test-auth:
pytest tests/test_auth.py -v
test-products:
pytest tests/test_products.py -v
test-stock:
pytest tests/test_stock.py -v
test-marketplace:
pytest tests/test_marketplace.py -v
test-admin:
pytest tests/test_admin.py -v
# Code quality (skip check-tools for now)
lint:
@echo Running flake8...
flake8 . --max-line-length=120 --extend-ignore=E203,W503,I201,I100 --exclude=venv,__pycache__,.git
@echo Running mypy...
mypy . --ignore-missing-imports --exclude venv
format:
@echo Running black...
black . --exclude venv
@echo Running isort...
isort . --skip venv
# Combined format and lint
check: format lint
# Combined test with coverage and linting
ci: format lint test-coverage
# Database-aware CI pipeline
ci-db: format lint migrate-check test-coverage
@echo ✅ CI pipeline with database checks completed
# Database migrations
migrate-create:
@if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create message="your_description") else (alembic revision --autogenerate -m "$(message)")
migrate-create-manual:
@if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create-manual message="your_description") else (alembic revision -m "$(message)")
migrate-up:
@echo Running database migrations...
alembic upgrade head
@echo ✅ Migrations completed successfully
migrate-down:
@echo Rolling back last migration...
alembic downgrade -1
@echo ✅ Rollback completed
migrate-down-to:
@if "$(revision)"=="" (echo Error: Please provide revision. Usage: make migrate-down-to revision="revision_id") else (alembic downgrade $(revision))
migrate-reset:
@echo Resetting database...
alembic downgrade base
alembic upgrade head
@echo ✅ Database reset completed
migrate-status:
@echo 📊 Current migration status:
alembic current
@echo.
@echo 📋 Migration history:
alembic history --verbose
migrate-show:
@if "$(revision)"=="" (echo Error: Please provide revision. Usage: make migrate-show revision="revision_id") else (alembic show $(revision))
migrate-heads:
@echo 📍 Current migration heads:
alembic heads
migrate-check:
@echo 🔍 Checking for pending migrations...
@python -c "from alembic import command, config; cfg = config.Config('alembic.ini'); command.check(cfg)" && echo "✅ No pending migrations" || echo "⚠️ Pending migrations found"
# Database initialization (enhanced)
db-init: migrate-up
@echo 🚀 Database initialization completed
db-fresh: migrate-reset
@echo 🔄 Fresh database setup completed
# Database backup before risky operations (if using PostgreSQL/MySQL)
backup-db:
@echo 💾 Creating database backup...
@python scripts/backup_database.py
@echo ✅ Database backup created
# === FRESH START COMMANDS (Development) ===
fresh-backup:
@echo 💾 Creating backup of current state...
@if not exist scripts mkdir scripts
@python scripts/backup_database.py
fresh-clean:
@echo 🧹 Cleaning up for fresh start...
@if exist ecommerce.db del ecommerce.db
@if exist alembic\versions\*.py (for %%f in (alembic\versions\*.py) do if not "%%~nf"=="__init__" del "%%f")
@echo ✅ Cleanup completed
fresh-setup: fresh-backup fresh-clean
@echo 🚀 Setting up fresh database with proper migrations...
@echo.
@echo Step 1: Creating initial migration from models...
alembic revision --autogenerate -m "initial_schema_and_indexes"
@echo.
@echo Step 2: Running the migration to create database...
alembic upgrade head
@echo.
@echo ✅ Fresh setup completed!
@echo Database is now managed entirely by Alembic migrations.
# Check what the fresh migration would contain
fresh-preview:
@echo 🔍 Previewing what the fresh migration would contain...
@echo This will show what tables/indexes would be created.
@echo.
@if exist ecommerce.db (echo Current database detected - showing diff) else (echo No database - showing full schema)
alembic revision --autogenerate -m "preview_only" --head-only
# Complete development environment setup with fresh database
dev-fresh-setup: install-all fresh-setup
@echo 🎉 Complete fresh development setup completed!
@echo.
@echo What was done:
@echo ✅ All dependencies installed
@echo ✅ Database created with migrations
@echo ✅ Migration tracking initialized
@echo.
@echo Next steps:
@echo 1. Review the migration file in alembic/versions/
@echo 2. Add your custom indexes to the migration
@echo 3. Run 'make dev' to start development
@echo 4. Use 'make migrate-create message="description"' for future changes
# Verify the fresh setup worked
verify-fresh:
@echo 🔍 Verifying fresh setup...
@echo.
@echo Migration status:
@alembic current
@echo.
@echo Database tables:
@python -c "from sqlalchemy import create_engine, text; engine = create_engine('sqlite:///./ecommerce.db'); print('Tables:', [r[0] for r in engine.execute(text('SELECT name FROM sqlite_master WHERE type=\"table\"')).fetchall()])"
@echo.
@echo ✅ Verification completed
# Docker commands
docker-build:
docker-compose build
docker-up:
docker-compose up -d
docker-down:
docker-compose down
docker-logs:
docker-compose logs -f api
docker-restart: docker-down docker-up
# Pre-deployment checks
pre-deploy: qa migrate-status
@echo 🚀 Pre-deployment checks completed!
@echo Ready for deployment.
# Production deployment
deploy-staging: migrate-up
docker-compose -f docker-compose.staging.yml up -d
deploy-prod: migrate-up
docker-compose -f docker-compose.prod.yml up -d
# Documentation deployment workflow
docs-publish: docs-build docs-deploy
@echo Documentation published successfully!
@echo Visit: https://yourusername.github.io/letzshop-import/
docs-preview: docs-build
@echo Opening documentation preview...
@start site\index.html
# Clean up (Windows compatible)
clean:
@if exist htmlcov rmdir /s /q htmlcov
@if exist .pytest_cache rmdir /s /q .pytest_cache
@if exist .coverage del .coverage
@if exist .mypy_cache rmdir /s /q .mypy_cache
@for /d /r . %%d in (__pycache__) do @if exist "%%d" rmdir /s /q "%%d"
@del /s /q *.pyc 2>nul || echo No .pyc files found
clean-all: clean docs-clean
@echo All build artifacts cleaned!
# Development workflow shortcuts
setup: install-all db-init
@echo Development environment setup complete!
@echo Run 'make dev-full' to start both API and documentation servers
setup-fresh: install-all db-fresh
@echo Fresh development environment setup complete!
@echo Run 'make dev-full' to start both API and documentation servers
setup-test: install-test
@echo Test environment setup complete!
setup-docs: install-docs
@echo Documentation environment setup complete!
@echo Run 'make docs-serve' to start documentation server
full-test: format lint test-coverage
@echo Full test suite completed!
# Quality assurance workflow
qa: format lint test-coverage docs-check
@echo Quality assurance checks completed!
# Release workflow
release-check: qa docs-build
@echo Release readiness check completed!
# Development workflow examples
workflow-new-feature:
@echo 🚀 Starting new feature development workflow:
@echo 1. Pulling latest changes and updating dependencies...
@$(MAKE) install-all
@echo 2. Running migrations...
@$(MAKE) migrate-up
@echo 3. Running tests to ensure clean state...
@$(MAKE) test-fast
@echo 4. Starting development environment...
@$(MAKE) dev-full
workflow-deploy:
@echo 🚀 Deployment workflow:
@echo 1. Running comprehensive checks...
@$(MAKE) pre-deploy-check
@echo 2. Ready for deployment!
@echo Run 'make deploy-staging' or 'make deploy-prod' to deploy.
# Help command
help:
@echo Available commands:
@echo.
@echo === SETUP ===
@echo install - Install production dependencies
@echo install-test - Install test dependencies only
@echo install-dev - Install all development dependencies
@echo install-docs - Install documentation dependencies
@echo install-all - Install everything
@echo setup - Complete development setup
@echo setup-test - Setup test environment only
@echo setup-docs - Setup documentation environment
@echo.
@echo === DEVELOPMENT ===
@echo dev - Start development server (API only)
@echo dev-with-docs - Start both API and documentation servers
@echo dev-full - Start full development environment with info
@echo.
@echo === DOCUMENTATION ===
@echo docs - Start documentation development server (alias for docs-serve)
@echo docs-serve - Start MkDocs development server
@echo docs-build - Build documentation site
@echo docs-deploy - Deploy documentation to GitHub Pages
@echo docs-publish - Build and deploy documentation
@echo docs-preview - Build and open documentation locally
@echo docs-update - Update docs with API information
@echo docs-check - Check documentation for issues
@echo docs-clean - Clean documentation build files
@echo.
@echo === TESTING ===
@echo test - Run all tests
@echo test-unit - Run unit tests only
@echo test-integration - Run integration tests only
@echo test-coverage - Run tests with coverage report
@echo test-fast - Run fast tests (exclude slow ones)
@echo test-slow - Run slow tests only
@echo full-test - Format, lint, and test with coverage
@echo.
@echo === CODE QUALITY ===
@echo format - Format code with black and isort
@echo lint - Run linting with flake8 and mypy
@echo check - Format and lint code
@echo ci - Full CI pipeline (format, lint, test)
@echo qa - Quality assurance (format, lint, test, docs check)
@echo.
@echo === DATABASE MIGRATIONS ===
@echo migrate-create message="msg" - Create auto-generated migration
@echo migrate-create-manual message="msg" - Create empty migration template
@echo migrate-up - Run all pending migrations
@echo migrate-down - Rollback last migration
@echo migrate-down-to revision="id" - Rollback to specific revision
@echo migrate-reset - Reset database to base and rerun all
@echo migrate-status - Show current migration status and history
@echo migrate-show revision="id" - Show specific migration details
@echo migrate-heads - Show current migration heads
@echo migrate-check - Check for pending migrations
@echo migrate-create-indexes - Create the database indexes migration
@echo db-init - Initialize database with migrations
@echo db-fresh - Fresh database setup
@echo.
@echo === DOCKER ===
@echo docker-build - Build Docker containers
@echo docker-up - Start Docker containers
@echo docker-down - Stop Docker containers
@echo docker-restart - Restart Docker containers
@echo.
@echo === CLEANUP ===
@echo clean - Remove test artifacts and cache files
@echo clean-all - Remove all build artifacts (including docs)
@echo.
@echo === WORKFLOWS ===
@echo release-check - Complete release readiness check
@echo.
@echo === QUICK START ===
@echo make setup # First time setup
@echo make dev-full # Start development environment
@echo make docs-serve # Start documentation server
@echo make qa # Run quality checks
# Help for fresh start
help-fresh:
@echo === FRESH START COMMANDS ===
@echo fresh-backup - Backup current database
@echo fresh-clean - Clean database and migrations
@echo fresh-setup - Complete fresh start with migrations
@echo fresh-preview - Preview what migration would create
@echo dev-fresh-setup - Complete development setup from scratch
@echo verify-fresh - Verify fresh setup worked correctly
@echo.
@echo RECOMMENDED WORKFLOW:
@echo make dev-fresh-setup # Complete setup
@echo # Edit the generated migration file to add indexes
@echo make dev # Start development