Files
thrillwiki_django_no_react/docs/MANAGEMENT_COMMANDS.md
pacnpal ca770d76ff Enhance documentation and management commands for ThrillWiki
- Updated backend README.md to include detailed management commands for configuration, database operations, cache management, data management, user authentication, content/media handling, trending/discovery, testing/development, and security/auditing.
- Added a new MANAGEMENT_COMMANDS.md file for comprehensive command reference.
- Included logging standardization details in architecture documentation (ADR-007).
- Improved production checklist with configuration validation and cache verification steps.
- Expanded API documentation to include error logging details.
- Created a documentation review checklist to ensure completeness and accuracy.
2025-12-23 21:28:14 -05:00

12 KiB

ThrillWiki Management Commands Reference

Complete reference for all Django management commands in ThrillWiki.

Quick Index

Configuration & Validation

validate_settings

Validate all environment variables and configuration settings.

Usage:

uv run manage.py validate_settings [options]

Options:

  • --strict - Treat warnings as errors
  • --json - Output results as JSON
  • --secrets-only - Only validate secrets

Example:

# Validate all settings
uv run manage.py validate_settings

# Strict mode for CI/CD
uv run manage.py validate_settings --strict

# JSON output for automation
uv run manage.py validate_settings --json

Exit Codes:

  • 0 - All validations passed
  • 1 - Validation failed

Related:


validate_state_machines

Validate all FSM state machine configurations.

Usage:

uv run manage.py validate_state_machines

Validates:

  • State transition definitions
  • Transition callbacks
  • State field configurations
  • Permission requirements

Related:


list_transition_callbacks

List all registered FSM transition callbacks.

Usage:

uv run manage.py list_transition_callbacks

Output:

  • Model name
  • Transition name
  • Callback function
  • Source states
  • Target state

Database Operations

migrate

Apply database migrations.

Usage:

uv run manage.py migrate [app_label] [migration_name]

Example:

# Apply all migrations
uv run manage.py migrate

# Apply specific app migrations
uv run manage.py migrate parks

# Migrate to specific migration
uv run manage.py migrate parks 0005

makemigrations

Create new migrations based on model changes.

Usage:

uv run manage.py makemigrations [app_label]

Example:

# Create migrations for all apps
uv run manage.py makemigrations

# Create migrations for specific app
uv run manage.py makemigrations parks

showmigrations

Show all migrations and their status.

Usage:

uv run manage.py showmigrations [app_label]

fix_migrations / fix_migration_history

Fix migration history issues.

Usage:

uv run manage.py fix_migrations
uv run manage.py fix_migration_history

Use Cases:

  • Resolve migration conflicts
  • Fix corrupted migration history
  • Synchronize migration state

reset_db

Reset the database (DESTRUCTIVE - development only).

Usage:

uv run manage.py reset_db

Warning: This command destroys all data. Only use in development.


Cache Management

warm_cache

Pre-populate cache with frequently accessed data.

Usage:

uv run manage.py warm_cache [options]

Options:

  • --dry-run - Show what would be cached without caching
  • --parks-only - Only warm park-related caches
  • --rides-only - Only warm ride-related caches
  • --metadata-only - Only warm filter metadata caches
  • --verbose - Show detailed output

Example:

# Warm all caches
uv run manage.py warm_cache

# Preview without caching
uv run manage.py warm_cache --dry-run

# Only warm park caches
uv run manage.py warm_cache --parks-only --verbose

Caches Warmed:

  • Park list (top 500)
  • Ride list (top 1000)
  • Popular parks (top 20 by ride count)
  • Top-rated rides (top 20 by rating)
  • Park/ride status counts
  • Filter metadata

Performance:

  • Typical execution time: 5-10 seconds
  • Reduces initial page load time by 50-70%

Related:


clear_cache

Clear all application caches.

Usage:

uv run manage.py clear_cache

Clears:

  • Default cache
  • Session cache
  • API cache
  • Template cache

Use Cases:

  • After data imports
  • After configuration changes
  • Troubleshooting cache issues

Data Management

seed_initial_data

Seed initial reference data (operators, manufacturers, etc.).

Usage:

uv run manage.py seed_initial_data

Creates:

  • Major park operators (Disney, Universal, Six Flags, Cedar Fair)
  • Ride manufacturers (Intamin, B&M, RMC, Vekoma)
  • Ride designers
  • Initial categories and types

Idempotent: Safe to run multiple times (uses get_or_create)


create_sample_data

Create comprehensive sample data for development.

Usage:

uv run manage.py create_sample_data [options]

Options:

  • --minimal - Create minimal data for quick testing
  • --clear - Delete existing data before creating

Creates:

  • 10-15 parks (major theme parks, regional parks, water parks)
  • 50-100 rides (coasters, flat rides, water rides)
  • 20-30 companies (operators, manufacturers)
  • 10 test users
  • 100-200 reviews
  • 50 photos

Example:

# Full sample data
uv run manage.py create_sample_data

# Minimal for quick testing
uv run manage.py create_sample_data --minimal

# Clear and recreate
uv run manage.py create_sample_data --clear

Related:


seed_sample_data

Seed sample parks and rides.

Usage:

uv run manage.py seed_sample_data

seed_submissions

Seed test submissions for moderation testing.

Usage:

uv run manage.py seed_submissions

seed_data

Seed API test data.

Usage:

uv run manage.py seed_data

update_park_counts

Update park statistics (ride counts, ratings).

Usage:

uv run manage.py update_park_counts

Updates:

  • Total ride count per park
  • Roller coaster count per park
  • Average rating per park
  • Review count per park

update_ride_rankings

Update ride rankings.

Usage:

uv run manage.py update_ride_rankings

Updates:

  • Global ride rankings
  • Category-specific rankings
  • Winning percentages
  • Head-to-head comparisons

User & Authentication

create_test_users

Create test users for development.

Usage:

uv run manage.py create_test_users

Creates:

  • Admin user
  • Moderator user
  • Regular test users

delete_user

Delete a user and all related data.

Usage:

uv run manage.py delete_user <username>

Example:

uv run manage.py delete_user testuser

setup_groups

Setup user groups and permissions.

Usage:

uv run manage.py setup_groups

Creates:

  • Moderators group
  • Editors group
  • Contributors group
  • Appropriate permissions for each group

setup_site

Setup Django sites framework.

Usage:

uv run manage.py setup_site

Social Authentication Commands

# Full social auth setup
uv run manage.py setup_social_auth

# Setup social providers
uv run manage.py setup_social_providers

# Create social apps
uv run manage.py create_social_apps

# Check social apps configuration
uv run manage.py check_social_apps

# Fix social apps issues
uv run manage.py fix_social_apps

# Reset social apps
uv run manage.py reset_social_apps

# Reset all social auth
uv run manage.py reset_social_auth

# Cleanup social auth
uv run manage.py cleanup_social_auth

# Update social apps sites
uv run manage.py update_social_apps_sites

# Discord-specific
uv run manage.py verify_discord_settings
uv run manage.py test_discord_auth

# Check all social tables
uv run manage.py check_all_social_tables

# Setup social auth admin
uv run manage.py setup_social_auth_admin

Avatar Management

# Generate letter avatars
uv run manage.py generate_letter_avatars

# Regenerate all avatars
uv run manage.py regenerate_avatars

Content & Media

collectstatic

Collect static files for deployment.

Usage:

uv run manage.py collectstatic [--noinput]

Example:

# Interactive
uv run manage.py collectstatic

# Non-interactive (for CI/CD)
uv run manage.py collectstatic --noinput

optimize_static

Minify and compress static files.

Usage:

uv run manage.py optimize_static

Media File Commands

# Download photos
uv run manage.py download_photos

# Move photos to correct locations
uv run manage.py move_photos

# Fix photo path issues
uv run manage.py fix_photo_paths

Calculate trending content.

Usage:

uv run manage.py calculate_trending

Calculates:

  • Trending parks (based on views, reviews, activity)
  • Trending rides (based on views, reviews, activity)
  • Trending users (based on contributions)

Update trending content.

Usage:

uv run manage.py update_trending

Test trending calculation.

Usage:

uv run manage.py test_trending

calculate_new_content

Calculate new content for discovery.

Usage:

uv run manage.py calculate_new_content

Testing & Development

rundev

Run development server with auto-reload.

Usage:

uv run manage.py rundev

Features:

  • Auto-reload on file changes
  • Debug mode enabled
  • Development settings

setup_dev

Setup development environment.

Usage:

uv run manage.py setup_dev

Performs:

  • Creates required directories
  • Generates development config files
  • Sets up development database

test_location

Test location services.

Usage:

uv run manage.py test_location

test_transition_callbacks

Test FSM transition callbacks.

Usage:

uv run manage.py test_transition_callbacks

analyze_transitions

Analyze FSM transitions.

Usage:

uv run manage.py analyze_transitions

cleanup_test_data

Cleanup test data.

Usage:

uv run manage.py cleanup_test_data

Security & Auditing

security_audit

Run security audit.

Usage:

uv run manage.py security_audit

Checks:

  • Security header configuration
  • HTTPS settings
  • Cookie security
  • CSRF protection
  • Rate limiting configuration

Command Cheat Sheet

Task Command
Validate configuration uv run manage.py validate_settings --strict
Warm cache uv run manage.py warm_cache
Clear cache uv run manage.py clear_cache
Seed initial data uv run manage.py seed_initial_data
Create sample data uv run manage.py create_sample_data --minimal
Run development server uv run manage.py rundev
Setup development uv run manage.py setup_dev
Create test users uv run manage.py create_test_users
Update trending uv run manage.py calculate_trending
Security audit uv run manage.py security_audit

Common Workflows

Initial Development Setup

uv run manage.py migrate
uv run manage.py createsuperuser
uv run manage.py setup_groups
uv run manage.py seed_initial_data
uv run manage.py create_sample_data --minimal
uv run manage.py warm_cache
uv run manage.py rundev

Production Deployment

uv run manage.py validate_settings --strict
uv run manage.py migrate
uv run manage.py collectstatic --noinput
uv run manage.py warm_cache

Cache Refresh After Data Import

uv run manage.py clear_cache
uv run manage.py update_park_counts
uv run manage.py update_ride_rankings
uv run manage.py calculate_trending
uv run manage.py warm_cache

Development Reset

uv run manage.py reset_db
uv run manage.py migrate
uv run manage.py create_sample_data
uv run manage.py warm_cache

Social Auth Setup

uv run manage.py setup_site
uv run manage.py setup_social_auth
uv run manage.py check_social_apps

Full Test Environment

uv run manage.py migrate
uv run manage.py seed_initial_data
uv run manage.py create_sample_data
uv run manage.py create_test_users
uv run manage.py seed_submissions
uv run manage.py warm_cache