diff --git a/Makefile b/Makefile index c17a13da..8790cbc4 100644 --- a/Makefile +++ b/Makefile @@ -1,97 +1,82 @@ -# 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 +# LetzShop API Makefile (Windows Compatible) +.PHONY: install install-dev install-docs install-all dev test test-coverage lint format check docker-build docker-up docker-down 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) +# ============================================================================= +# INSTALLATION & SETUP +# ============================================================================= -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-dev: install + pip install -r requirements-dev.txt + install-test: pip install -r tests/requirements-test.txt -install-dev: - pip install -r requirements.txt - pip install -r requirements-dev.txt - install-docs: pip install -r requirements-docs.txt -install-all: install install-test install-dev install-docs +install-all: install install-dev install-test install-docs + +setup: install-all migrate-up + @echo Development environment setup complete! + @echo Run 'make dev' to start development server + +# ============================================================================= +# DEVELOPMENT SERVERS +# ============================================================================= -# Development servers dev: uvicorn main:app --reload --host 0.0.0.0 --port 8000 -# Safe development startup (checks migrations first) -# Development workflow with migration check -dev-safe: migrate-check dev - @echo Development server started with migration check - dev-with-docs: - @echo Starting API server and documentation server... + @echo Starting API and documentation servers... @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 +# ============================================================================= +# DATABASE MIGRATIONS +# ============================================================================= -# Documentation commands -docs: docs-serve +migrate-create: + @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create message="your_description") else (alembic revision --autogenerate -m "$(message)") -docs-serve: - @echo Starting MkDocs development server... - mkdocs serve --dev-addr=0.0.0.0:8001 +migrate-create-manual: + @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create-manual message="your_description") else (alembic revision -m "$(message)") -docs-build: - @echo Building documentation site... - mkdocs build --clean --strict +migrate-up: + @echo Running database migrations... + alembic upgrade head + @echo Migrations completed successfully -docs-build-quiet: - @echo Building documentation (quiet)... - mkdocs build --clean --quiet +migrate-down: + @echo Rolling back last migration... + alembic downgrade -1 + @echo Rollback completed -docs-deploy: - @echo Deploying documentation to GitHub Pages... - mkdocs gh-deploy --clean +migrate-status: + @echo Current migration status: + alembic current + @echo. + @echo Migration history: + alembic history --verbose -docs-deploy-force: - @echo Force deploying documentation to GitHub Pages... - mkdocs gh-deploy --clean --force +backup-db: + @echo Creating database backup... + @python scripts/backup_database.py -docs-update: - @echo Updating documentation with API information... - python scripts/update_docs.py +# ============================================================================= +# TESTING +# ============================================================================= -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 @@ -107,10 +92,6 @@ test-coverage: 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 @@ -120,18 +101,9 @@ test-products: 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 +# ============================================================================= +# CODE QUALITY +# ============================================================================= format: @echo Running black... @@ -139,126 +111,49 @@ format: @echo Running isort... isort . --skip venv +lint: + @echo Running linting... + flake8 . --max-line-length=120 --extend-ignore=E203,W503,I201,I100 --exclude=venv,__pycache__,.git + mypy . --ignore-missing-imports --exclude 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 +# Quality assurance workflow +qa: format lint test-coverage docs-check + @echo Quality assurance 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)") +# ============================================================================= +# DOCUMENTATION +# ============================================================================= -migrate-create-manual: - @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create-manual message="your_description") else (alembic revision -m "$(message)") +docs-serve: + @echo Starting documentation server... + mkdocs serve --dev-addr=0.0.0.0:8001 -migrate-up: - @echo [MIGRATE] Running database migrations... - alembic upgrade head - @echo [MIGRATE] Migrations completed successfully +docs-build: + @echo Building documentation... + mkdocs build --clean --strict -migrate-down: - @echo [MIGRATE] Rolling back last migration... - alembic downgrade -1 - @echo [MIGRATE] Rollback completed +docs-deploy: + @echo Deploying documentation... + mkdocs gh-deploy --clean -migrate-down-to: - @if "$(revision)"=="" (echo Error: Please provide revision. Usage: make migrate-down-to revision="revision_id") else (alembic downgrade $(revision)) +docs-clean: + @if exist site rmdir /s /q site + @echo Documentation build files cleaned! -migrate-reset: - @echo [MIGRATE] Resetting database... - alembic downgrade base - alembic upgrade head - @echo [MIGRATE] Database reset completed +docs-check: + @echo Checking documentation for issues... + mkdocs build --strict --verbose -migrate-status: - @echo [STATUS] Current migration status: - alembic current - @echo. - @echo [HISTORY] Migration history: - alembic history --verbose +# ============================================================================= +# DOCKER +# ============================================================================= -migrate-show: - @if "$(revision)"=="" (echo Error: Please provide revision. Usage: make migrate-show revision="revision_id") else (alembic show $(revision)) - -migrate-heads: - @echo [INFO] Current migration heads: - alembic heads - -migrate-check: - @echo [CHECK] Checking for pending migrations... - @python -c "from alembic import command, config; cfg = config.Config('alembic.ini'); command.check(cfg)" && echo "[CHECK] No pending migrations" || echo "[WARNING] Pending migrations found" - -# Create the index migration we discussed -migrate-create-indexes: - @echo [CREATE] Creating index migration... - alembic revision -m "add_database_indexes" - @echo [CREATE] Index migration created. Please edit the file to add your indexes. - -# Database initialization (enhanced) -db-init: migrate-up - @echo [INIT] Database initialization completed - -db-fresh: migrate-reset - @echo [INIT] Fresh database setup completed - -# === FRESH START COMMANDS (Development) === -fresh-backup: - @echo [BACKUP] Creating backup of current state... - @if not exist scripts mkdir scripts - @python scripts/backup_database.py - -fresh-clean: - @echo [CLEAN] 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 [CLEAN] Cleanup completed - -fresh-setup: fresh-backup fresh-clean - @echo [SETUP] 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 [SETUP] Fresh setup completed! - @echo Database is now managed entirely by Alembic migrations. - -# Check what the fresh migration would contain -fresh-preview: - @echo [PREVIEW] Showing 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 [SUCCESS] Complete fresh development setup completed! - @echo. - @echo What was done: - @echo [OK] All dependencies installed - @echo [OK] Database created with migrations - @echo [OK] 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 [VERIFY] Running comprehensive verification... - @python scripts/verify_setup.py - -# Docker commands docker-build: docker-compose build @@ -268,33 +163,22 @@ docker-up: 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 [DEPLOY] Pre-deployment checks completed! - @echo Ready for deployment. +# ============================================================================= +# DEPLOYMENT +# ============================================================================= -# Production deployment with migrations 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/ +# ============================================================================= +# UTILITIES +# ============================================================================= -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 @@ -303,266 +187,82 @@ clean: @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 -# Enhanced setup commands -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. - -# Create missing __init__.py files -fix-init-files: - @echo [FIX] Creating missing __init__.py files... - @if not exist models\__init__.py (echo # models/__init__.py > models\__init__.py && echo Created models\__init__.py) - @if not exist models\database\__init__.py (echo # models/database/__init__.py > models\database\__init__.py && echo Created models\database\__init__.py) - @if not exist models\api\__init__.py (echo # models/api/__init__.py > models\api\__init__.py && echo Created models\api\__init__.py) - @echo [FIX] Init files created - -# Test model imports separately -test-database-imports: - @echo [TEST] Testing database model imports... - @python -c "from models.database.base import Base; print('✓ Base imported:', type(Base)); print('✓ Base metadata tables:', list(Base.metadata.tables.keys()))" - -test-api-imports: - @echo [TEST] Testing API model imports... - @python -c "import models.api; print('✓ API models package imported')" - -test-all-imports: - @echo [TEST] Testing all model imports... - @python -c "from models import Base, User, Product, Stock; print('✓ Database models imported'); print('✓ Found tables:', list(Base.metadata.tables.keys())); import models.api; print('✓ API models imported')" - -# Enhanced migration fix with better error handling -fix-migration: fix-init-files - @echo [FIX] Fixing migration with proper model imports... - @echo Step 1: Testing imports first... - @$(MAKE) test-database-imports - @echo Step 2: Removing current migration... - @alembic downgrade base || echo "No migrations to downgrade" - @echo Step 3: Deleting migration files... - @for %%f in (alembic\versions\*.py) do if not "%%~nf"=="__init__" del "%%f" - @echo Step 4: Creating new migration with all models... - @alembic revision --autogenerate -m "initial_complete_schema" - @echo Step 5: Applying new migration... - @alembic upgrade head - @echo [FIX] Migration fix completed! - -# Comprehensive project verification -verify-project: - @echo [VERIFY] Comprehensive project verification... - @echo. - @echo Testing database models: - @$(MAKE) test-database-imports - @echo. - @echo Testing API models: - @$(MAKE) test-api-imports - @echo. - @echo Database verification: +verify-setup: + @echo Running setup verification... @python scripts/verify_setup.py - @echo. - @echo [VERIFY] Project verification completed! -# Complete fresh restart for your project structure -fresh-restart: test-all-imports fix-migration verify-project - @echo [SUCCESS] Complete fresh restart with full project structure completed! - @echo. - @echo Your project now has: - @echo ✓ Database models (SQLAlchemy) for data storage - @echo ✓ API models (Pydantic) for request/response validation - @echo ✓ Proper Alembic migrations - @echo ✓ All imports working correctly - @echo. - @echo Next steps: - @echo 1. Run 'make dev' to start your API server - @echo 2. Visit http://localhost:8000/docs for API documentation - @echo 3. Use 'make migrate-create message="description"' for future changes +# ============================================================================= +# HELP +# ============================================================================= -# Simple fix commands - add to your Makefile - -# Simple fix for import issues -simple-fix: - @echo [SIMPLE-FIX] Running simple import fix... - @python scripts/simple_fix.py - -# Test imports one by one -test-step-by-step: - @echo [TEST] Testing imports step by step... - @python -c "from models.database.base import Base; print('✓ Base OK:', len(Base.metadata.tables), 'tables')" - @python -c "from models.database.user import User; print('✓ User OK')" - @python -c "from models.database.product import Product; print('✓ Product OK')" - @python -c "from models.database.stock import Stock; print('✓ Stock OK')" - @python -c "from models.database.shop import Shop; print('✓ Shop OK')" - @python -c "from models.database.marketplace import MarketplaceImportJob; print('✓ Marketplace OK')" - -# Simple migration fix -simple-migration-fix: - @echo [MIGRATION] Simple migration fix... - @echo Step 1: Remove old migration... - @alembic downgrade base || echo "No migration to downgrade" - @echo Step 2: Delete migration files... - @for %%f in (alembic\versions\*.py) do if not "%%~nf"=="__init__" del "%%f" - @echo Step 3: Create new migration... - @alembic revision --autogenerate -m "complete_schema" - @echo Step 4: Apply migration... - @alembic upgrade head - @echo [MIGRATION] Done! - -# Complete simple workflow -simple-restart: simple-fix test-step-by-step simple-migration-fix verify-fresh - @echo [SUCCESS] Simple restart completed! - -# Help command help: - @echo Available commands: + @echo LetzShop API Development 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 install - Install production dependencies + @echo install-test - Install test dependencies only + @echo install-dev - Install development dependencies + @echo install-all - Install all dependencies + @echo setup - Complete development setup @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 dev - Start API development server + @echo dev-full - Start API and documentation servers @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 === DATABASE === + @echo migrate-create message="msg" - Create new migration + @echo migrate-up - Apply pending migrations + @echo migrate-down - Rollback last migration + @echo migrate-status - Show migration status + @echo backup-db - Backup database @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 test - Run all tests + @echo test-coverage - Run tests with coverage + @echo test-fast - Run fast tests only @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 format - Format code (black + isort) + @echo lint - Run linting (flake8 + mypy) + @echo check - Format + lint + @echo ci - Full CI pipeline + @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 === DOCUMENTATION === + @echo docs-serve - Start documentation server + @echo docs-build - Build documentation @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 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 === DEPLOYMENT === + @echo deploy-staging - Deploy to staging environment + @echo deploy-prod - Deploy to production environment @echo. - @echo === WORKFLOWS === - @echo release-check - Complete release readiness check + @echo === UTILITIES === + @echo clean - Clean build artifacts + @echo verify-setup - Verify project setup @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 + @echo === DAILY WORKFLOW === + @echo make dev # Start development + @echo make migrate-create message="feature" # Create migration + @echo make migrate-up # Apply migration + @echo make test # Run tests -# Help for migration -help-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 +help-db: + @echo === DATABASE COMMANDS === + @echo migrate-create message="description" - Create auto-generated migration + @echo migrate-create-manual message="desc" - Create empty migration template + @echo migrate-up - Apply all pending migrations + @echo migrate-down - Rollback last migration + @echo migrate-status - Show current status and history + @echo backup-db - Create database backup @echo. - -# 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 + @echo TYPICAL WORKFLOW: + @echo 1. Edit your SQLAlchemy models + @echo 2. make migrate-create message="add_new_feature" + @echo 3. Review the generated migration file + @echo 4. make migrate-up \ No newline at end of file diff --git a/tests/requirements-test.txt b/requirements-test.txt similarity index 100% rename from tests/requirements-test.txt rename to requirements-test.txt