|
| 1 | +# Tux Database Operations Makefile |
| 2 | +# Use this to test database operations without the CLI |
| 3 | + |
| 4 | +.PHONY: help help-db db-connect db-current db-upgrade db-downgrade db-revision db-reset db-init test-unit test-integration test-e2e test-db test-alembic test-migrations test-models test-controllers test-service test-db-all test-coverage test-smoke test-clean |
| 5 | + |
| 6 | +# Default target |
| 7 | +help: |
| 8 | + @echo "Tux Database Operations" |
| 9 | + @echo "=======================" |
| 10 | + @echo "" |
| 11 | + @echo "Available targets:" |
| 12 | + @echo " help - Show this help message" |
| 13 | + @echo " help-db - Show database-specific help" |
| 14 | + @echo "" |
| 15 | + @echo "Database Operations:" |
| 16 | + @echo " db-connect - Test database connection" |
| 17 | + @echo " db-current - Show current migration version" |
| 18 | + @echo " db-upgrade - Upgrade database to latest migration" |
| 19 | + @echo " db-downgrade - Downgrade database by one migration" |
| 20 | + @echo " db-revision - Create new migration revision" |
| 21 | + @echo " db-reset - Reset database (WARNING: destroys data)" |
| 22 | + @echo " db-init - Initialize database schema" |
| 23 | + @echo "" |
| 24 | + @echo "Testing:" |
| 25 | + @echo " test-unit - Run unit tests" |
| 26 | + @echo " test-integration - Run integration tests" |
| 27 | + @echo " test-e2e - Run end-to-end tests" |
| 28 | + @echo " test-db - Run all database tests" |
| 29 | + @echo " test-db-all - Run comprehensive database test suite" |
| 30 | + @echo "" |
| 31 | + @echo "Environment variables:" |
| 32 | + @echo " MODE=dev|prod - Environment mode (default: dev)" |
| 33 | + @echo "" |
| 34 | + @echo "Examples:" |
| 35 | + @echo " make db-connect" |
| 36 | + @echo " make MODE=prod db-current" |
| 37 | + @echo " make db-upgrade" |
| 38 | + |
| 39 | +# Environment setup |
| 40 | +MODE ?= dev |
| 41 | +PYTHON := uv run python |
| 42 | + |
| 43 | +# Database connection test |
| 44 | +db-connect: |
| 45 | + @echo "🔍 Testing database connection..." |
| 46 | + @MODE=$(MODE) $(PYTHON) scripts/db_connect_test.py |
| 47 | + |
| 48 | +# Show current migration |
| 49 | +db-current: |
| 50 | + @echo "📊 Getting current migration version..." |
| 51 | + @MODE=$(MODE) $(PYTHON) scripts/db_current.py |
| 52 | + |
| 53 | +# Upgrade database |
| 54 | +db-upgrade: |
| 55 | + @echo "⬆️ Upgrading database to latest migration..." |
| 56 | + @MODE=$(MODE) $(PYTHON) scripts/db_upgrade.py |
| 57 | + |
| 58 | +# Downgrade database |
| 59 | +db-downgrade: |
| 60 | + @echo "⬇️ Downgrading database by one migration..." |
| 61 | + @MODE=$(MODE) $(PYTHON) scripts/db_downgrade.py |
| 62 | + |
| 63 | +# Create new migration |
| 64 | +db-revision: |
| 65 | + @echo "📝 Creating new migration revision..." |
| 66 | + @MODE=$(MODE) $(PYTHON) scripts/db_revision.py |
| 67 | + |
| 68 | +# Initialize database schema |
| 69 | +db-init: |
| 70 | + @echo "🏗️ Initializing database schema..." |
| 71 | + @MODE=$(MODE) $(PYTHON) scripts/db_init.py |
| 72 | + |
| 73 | +# Reset database (DANGER!) |
| 74 | +db-reset: |
| 75 | + @echo "⚠️ WARNING: This will reset the database and destroy all data!" |
| 76 | + @read -p "Are you sure? (type 'yes' to continue): " confirm && [ "$$confirm" = "yes" ] || (echo "Operation cancelled" && exit 1) |
| 77 | + @echo "🔄 Resetting database..." |
| 78 | + @MODE=$(MODE) $(PYTHON) scripts/db_reset.py |
| 79 | + |
| 80 | +# ============================================================================ |
| 81 | +# TESTING TARGETS |
| 82 | +# ============================================================================ |
| 83 | + |
| 84 | +# Run all database unit tests |
| 85 | +test-unit: |
| 86 | + @echo "🧪 Running database unit tests..." |
| 87 | + $(PYTHON) -m pytest tests/unit/ -v --tb=short |
| 88 | + |
| 89 | +# Run database integration tests |
| 90 | +test-integration: |
| 91 | + @echo "🔗 Running database integration tests..." |
| 92 | + $(PYTHON) -m pytest --run-integration tests/integration/ -v --tb=short |
| 93 | + |
| 94 | +# Run database end-to-end tests |
| 95 | +test-e2e: |
| 96 | + @echo "🌍 Running database E2E tests..." |
| 97 | + $(PYTHON) -m pytest --run-e2e tests/e2e/ -v --tb=short |
| 98 | + |
| 99 | +# Run all database tests |
| 100 | +test-db: test-unit test-integration test-e2e |
| 101 | + @echo "✅ All database tests completed!" |
| 102 | + |
| 103 | +# Run pytest-alembic tests |
| 104 | +test-alembic: |
| 105 | + @echo "🗃️ Running pytest-alembic tests..." |
| 106 | + $(PYTHON) -m pytest --test-alembic -v --tb=short |
| 107 | + |
| 108 | +# Run migration-specific tests |
| 109 | +test-migrations: |
| 110 | + @echo "🔄 Running migration tests..." |
| 111 | + $(PYTHON) -m pytest tests/unit/test_database_migrations.py -v --tb=short |
| 112 | + |
| 113 | +# Run model-specific tests |
| 114 | +test-models: |
| 115 | + @echo "📊 Running model tests..." |
| 116 | + $(PYTHON) -m pytest tests/unit/test_database_models.py -v --tb=short |
| 117 | + |
| 118 | +# Run controller-specific tests |
| 119 | +test-controllers: |
| 120 | + @echo "🎛️ Running controller tests..." |
| 121 | + $(PYTHON) -m pytest tests/unit/test_database_controllers.py -v --tb=short |
| 122 | + |
| 123 | +# Run database service tests |
| 124 | +test-service: |
| 125 | + @echo "🔧 Running database service tests..." |
| 126 | + $(PYTHON) -m pytest tests/unit/test_database_service.py -v --tb=short |
| 127 | + |
| 128 | +# Comprehensive database test suite |
| 129 | +test-db-all: test-alembic test-migrations test-models test-controllers test-service test-integration test-e2e |
| 130 | + @echo "🎉 Complete database test suite passed!" |
| 131 | + |
| 132 | +# Run database tests with coverage |
| 133 | +test-coverage: |
| 134 | + @echo "📊 Running database tests with coverage..." |
| 135 | + $(PYTHON) -m pytest --cov=tux.database --cov-report=html --cov-report=term tests/unit/ tests/integration/ tests/e2e/ |
| 136 | + |
| 137 | +# Quick smoke test for database functionality |
| 138 | +test-smoke: |
| 139 | + @echo "🚀 Running database smoke tests..." |
| 140 | + @make db-connect || (echo "❌ Database connection failed" && exit 1) |
| 141 | + @make db-current || (echo "❌ Database current check failed" && exit 1) |
| 142 | + @echo "✅ Database smoke tests passed!" |
| 143 | + |
| 144 | +# Clean test artifacts |
| 145 | +test-clean: |
| 146 | + @echo "🧹 Cleaning test artifacts..." |
| 147 | + rm -rf .pytest_cache/ |
| 148 | + rm -rf tests/**/__pycache__/ |
| 149 | + rm -rf htmlcov/ |
| 150 | + rm -f .coverage |
| 151 | + |
| 152 | +# ============================================================================ |
| 153 | +# DEVELOPMENT HELPERS |
| 154 | +# ============================================================================ |
| 155 | + |
| 156 | +# Show available database targets |
| 157 | +help-db: |
| 158 | + @echo "Database Management Targets:" |
| 159 | + @echo " db-connect - Test database connection" |
| 160 | + @echo " db-current - Show current migration version" |
| 161 | + @echo " db-upgrade - Upgrade database to latest migration" |
| 162 | + @echo " db-downgrade - Downgrade database by one migration" |
| 163 | + @echo " db-revision - Create new migration revision" |
| 164 | + @echo " db-init - Initialize database schema" |
| 165 | + @echo " db-reset - Reset database (DANGER!)" |
| 166 | + @echo "" |
| 167 | + @echo "Database Testing Targets:" |
| 168 | + @echo " test-unit - Run all unit tests" |
| 169 | + @echo " test-integration - Run integration tests" |
| 170 | + @echo " test-e2e - Run end-to-end tests" |
| 171 | + @echo " test-db - Run unit + integration + e2e tests" |
| 172 | + @echo " test-db-all - Run comprehensive database test suite" |
| 173 | + @echo " test-alembic - Run pytest-alembic tests" |
| 174 | + @echo " test-migrations - Run migration-specific tests" |
| 175 | + @echo " test-models - Run model-specific tests" |
| 176 | + @echo " test-controllers - Run controller-specific tests" |
| 177 | + @echo " test-service - Run database service tests" |
| 178 | + @echo " test-coverage - Run tests with coverage report" |
| 179 | + @echo " test-smoke - Quick smoke test (connection + current)" |
| 180 | + @echo " test-clean - Clean test artifacts" |
| 181 | + @echo "" |
| 182 | + @echo "Usage examples:" |
| 183 | + @echo " make db-connect" |
| 184 | + @echo " make MODE=prod db-current" |
| 185 | + @echo " make test-unit" |
| 186 | + @echo " make test-db" |
| 187 | + @echo " make test-alembic" |
| 188 | + @echo " make test-db-all" |
0 commit comments