QC check
This commit is contained in:
199
Makefile
199
Makefile
@@ -32,12 +32,27 @@ install-all: install install-test install-dev install-docs
|
||||
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
|
||||
|
||||
@@ -77,13 +92,6 @@ docs-check:
|
||||
docs-help:
|
||||
mkdocs --help
|
||||
|
||||
# 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
|
||||
|
||||
# Testing commands
|
||||
test:
|
||||
pytest tests/ -v
|
||||
@@ -138,19 +146,125 @@ 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:
|
||||
alembic revision --autogenerate -m "$(message)"
|
||||
@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:
|
||||
@@ -167,11 +281,16 @@ docker-logs:
|
||||
|
||||
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:
|
||||
deploy-staging: migrate-up
|
||||
docker-compose -f docker-compose.staging.yml up -d
|
||||
|
||||
deploy-prod:
|
||||
deploy-prod: migrate-up
|
||||
docker-compose -f docker-compose.prod.yml up -d
|
||||
|
||||
# Documentation deployment workflow
|
||||
@@ -196,10 +315,14 @@ clean-all: clean docs-clean
|
||||
@echo All build artifacts cleaned!
|
||||
|
||||
# Development workflow shortcuts
|
||||
setup: install-all migrate-up
|
||||
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!
|
||||
|
||||
@@ -218,6 +341,25 @@ qa: format lint test-coverage docs-check
|
||||
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:
|
||||
@@ -264,10 +406,20 @@ help:
|
||||
@echo ci - Full CI pipeline (format, lint, test)
|
||||
@echo qa - Quality assurance (format, lint, test, docs check)
|
||||
@echo.
|
||||
@echo === DATABASE ===
|
||||
@echo migrate-up - Run database migrations
|
||||
@echo migrate-down - Rollback last migration
|
||||
@echo migrate-reset - Reset and rerun all migrations
|
||||
@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
|
||||
@@ -286,4 +438,19 @@ help:
|
||||
@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
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user