Skip to content

FastOpp 0.4.3 - Restructure oppman improve clean command

Pre-release
Pre-release

Choose a tag to compare

@codetricity codetricity released this 23 Oct 21:55
· 67 commits to main since this release
ec454e9

Django-Style Migration Commands & Demo Scripts Consolidation

Overview

This release introduces Django-style migration commands to oppman.py and consolidates all demo scripts into a unified scripts/demo/ directory structure. The changes improve developer experience by providing familiar Django-like commands while maintaining backward compatibility with existing Alembic functionality.

🚀 New Features

Django-Style Migration Commands

Added three new top-level commands to oppman.py that mirror Django's migration workflow:

  • makemigrations - Create new migration files (with optional message prompt)
  • sqlmigrate <revision> - Show SQL statements for a specific migration
  • showmigrations - Display migration status with [X] for applied and [ ] for pending

Enhanced Clean Command

The oppman.py clean command now includes comprehensive project cleanup and setup:

  • Complete Project Reset: Removes .git, .github, .cursor directories for fresh start
  • File Backup: Moves all demo files, docs, tests, and project metadata to backup
  • Interactive Setup Wizard: Prompts for project name, author, and description
  • Configuration Updates: Updates pyproject.toml with new metadata and resets version to "0.1.0"
  • Fresh README: Creates project-specific README.md with setup instructions

🏗️ Architecture Improvements

Modular oppman.py Structure

Refactored the monolithic oppman.py (856 lines → 201 lines, 76% reduction) into organized modules:

scripts/
├── commands/
│   ├── database.py      # Database operations
│   ├── server.py        # Server management
│   ├── users.py         # User management
│   └── project.py       # Project operations
└── help/
    └── text.py          # Help documentation

Demo Scripts Consolidation

Consolidated scattered demo scripts into a single location:

  • Before: Duplicate scripts in demo_scripts/ and scripts/
  • After: All demo scripts in scripts/demo/
  • Updated: All imports across oppdemo.py and routes/oppdemo.py

📝 Changes Made

Core Files Modified

  1. oppman.py - Modularized and added Django-style commands
  2. oppdemo.py - Updated imports and file management functions
  3. routes/oppdemo.py - Updated demo script imports
  4. scripts/migrate/cli.py - Added Django-style command handlers
  5. scripts/migrate/core.py - Added sqlmigrate() and show_migrations() methods
  6. scripts/commands/project.py - Enhanced clean command with comprehensive cleanup
  7. docs/DATABASE.md - Consolidated migration documentation
  8. docs/MIGRATION_GUIDE.md - Removed (consolidated into DATABASE.md)

New Files Created

  • scripts/commands/database.py - Database operations module
  • scripts/commands/server.py - Server management module
  • scripts/commands/users.py - User management module
  • scripts/commands/project.py - Project operations module
  • scripts/help/text.py - Help documentation module
  • scripts/demo/ - Consolidated demo scripts directory

Files Removed

  • oppman_new.py - Temporary file from modularization
  • docs/MIGRATION_GUIDE.md - Consolidated into DATABASE.md
  • Duplicate demo scripts from scripts/ directory
  • demo_scripts/ directory (moved to scripts/demo/)

🔧 Technical Details

Migration Command Implementation

# Django-style commands
uv run python oppman.py makemigrations [message]
uv run python oppman.py migrate
uv run python oppman.py sqlmigrate <revision>
uv run python oppman.py showmigrations

# Alembic-style commands (still supported)
uv run python oppman.py migrate init
uv run python oppman.py migrate upgrade
uv run python oppman.py migrate downgrade

Enhanced Clean Command Workflow

  1. Step 1: Run oppdemo.py destroy to switch to minimal app
  2. Step 2: Move remaining files to backup directory (including .git, .github, .cursor)
  3. Step 3: Interactive wizard for project setup
  4. Step 4: Update pyproject.toml and create new README.md

Files moved to backup during clean:

  • demo_assets/, base_assets/, scripts/demo/, docs/, tests/
  • oppdemo.py, pytest.ini, LICENSE, fastopp/, README.md
  • .github/, .cursor/, .git/ (project metadata for fresh start)

File Management Functions Updated

All oppdemo.py file management functions now properly handle scripts/demo/:

  • save_demo_files() - Backs up scripts/demo/ to demo_assets/scripts/
  • restore_demo_files() - Restores from demo_assets/scripts/ to scripts/demo/
  • destroy_demo_files() - Removes scripts/demo/ directory
  • diff_demo_files() - Compares scripts/demo/ with backup

✅ Testing

All functionality has been tested and verified:

  • ✅ Django-style migration commands work correctly
  • ✅ Enhanced clean command with interactive wizard
  • ✅ Demo script consolidation and imports
  • ✅ File management functions (save/restore/destroy/diff)
  • ✅ Web interface endpoints work with new structure
  • ✅ Backward compatibility with existing Alembic commands

🎯 Benefits

  1. Developer Experience: Familiar Django-like migration commands
  2. Code Organization: Modular structure improves maintainability
  3. Consistency: Unified demo script location eliminates confusion
  4. Maintainability: 76% reduction in main file size
  5. Backward Compatibility: All existing functionality preserved
  6. Project Setup: Streamlined project initialization with clean command

📚 Documentation Updates

  • Consolidated Migration Docs: Merged MIGRATION_GUIDE.md into DATABASE.md for better organization
  • Enhanced DATABASE.md: Added comprehensive Django-style command documentation
  • Updated Help Text: Added detailed help for all new commands
  • Usage Examples: Updated examples and usage instructions throughout

🔄 Migration Guide

For Existing Users

No breaking changes - all existing commands continue to work:

# Existing commands still work
uv run python oppman.py migrate init
uv run python oppman.py migrate upgrade
uv run python oppdemo.py init

# New Django-style commands available
uv run python oppman.py makemigrations
uv run python oppman.py showmigrations

For New Projects

Use the enhanced clean command for project setup:

uv run python oppman.py clean
# Follow interactive wizard prompts