Skip to content

Conversation

@pyramation
Copy link
Contributor

Add interactive --to flag for CLI revert command + Optimize recursive revert performance

Summary

This PR implements two related improvements to LaunchQL's revert functionality:

1. Performance Optimization for Recursive Reverts

  • Modified resolveWorkspaceExtensionDependencies() to optionally filter by deployed modules using database queries
  • Added getDeployedModules() helper method that queries the launchql_migrate schema to determine which packages are actually deployed
  • Updated recursive revert logic to only process modules that have been deployed to the database, eliminating wasted time processing undeployed modules
  • Made the method async to support database integration

2. Interactive CLI --to Flag Enhancement

  • Added interactive mode when --to flag is provided without a value (lql revert --to)
  • Implements two-step autocomplete selection: first select deployed package, then select specific change within that package
  • Uses LaunchQLMigrate.status() and getDeployedChanges() for real-time database querying
  • Maintains full backward compatibility with existing string-based --to usage
  • Includes graceful error handling and fallback when database is unavailable

Review & Testing Checklist for Human

  • Test interactive revert selection end-to-end - Run lql revert --to with deployed changes in database and verify two-step selection works correctly
  • Verify recursive revert performance improvement - Test recursive revert in workspace with mix of deployed/undeployed modules, confirm only deployed modules are processed
  • Test error handling edge cases - Verify graceful fallback when database unavailable, no deployed packages, or connection issues
  • Check backward compatibility - Ensure existing --to <string> usage still works and non-interactive revert commands unchanged
  • Validate TypeScript type safety - The interactive prompts use as any casting which could cause runtime errors if prompter response structure changes

Notes

Risk Areas:

  • Core method resolveWorkspaceExtensionDependencies() is now async and affects multiple callsites - could break untested code paths
  • Database integration adds new failure modes - error handling covers known cases but edge cases may exist
  • Interactive CLI functionality wasn't fully tested end-to-end due to DB connection issues during development

Performance Impact: The optimization should significantly improve recursive revert performance in large workspaces, but adds database queries that could potentially slow down other operations.

Link to Devin run: https://app.devin.ai/sessions/a5cdd2aebe714b9d835b800ce9f02915
Requested by: @pyramation

devin-ai-integration bot and others added 2 commits September 5, 2025 21:43
- Add getDeployedModules() method to query launchql_migrate.changes table
- Make resolveWorkspaceExtensionDependencies() async with optional deployment filtering
- Update revert() method to filter workspace extensions by deployment status
- Fix test file to handle async resolveWorkspaceExtensionDependencies() calls
- Add comprehensive REVERT.md documentation

This optimization prevents recursive revert from processing undeployed modules,
significantly improving performance for large workspaces.

Co-Authored-By: Dan Lynch <[email protected]>
- Add selectDeployedChange() function for two-step selection
- Query deployed packages using LaunchQLMigrate.status()
- Query deployed changes using LaunchQLMigrate.getDeployedChanges()
- Maintain backward compatibility with existing --to string usage
- Add autocomplete prompts for package and change selection
- Update usage text with interactive examples
- Handle graceful fallback when database is unavailable

Co-Authored-By: Dan Lynch <[email protected]>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 5 commits September 16, 2025 20:45
- Use target database parameter instead of default database
- Follow same pattern as deploy command with getPgEnvOptions({ database })
- Ensures interactive --to flag queries the correct target database

Co-Authored-By: Dan Lynch <[email protected]>
- Add optional preselectedPackage parameter to selectDeployedChange()
- Skip package selection when package already selected via --package or recursive mode
- Show only changes for preselected package to refine selection
- Maintain two-step selection (package then change) when no package preselected
- Improve user experience by reducing unnecessary prompts

Co-Authored-By: Dan Lynch <[email protected]>
- Update selectDeployedChange() to accept and use argv parameter
- Use 'package' and 'change' as question names to match CLI flags
- Pass argv to prompter.prompt() calls for automatic CLI argument passthrough
- Override existing package selection with scoped deployed packages when using --to
- Remove manual preselection logic in favor of inquirer's built-in handling
- Follow established pattern from deploy command and other CLI commands

Co-Authored-By: Dan Lynch <[email protected]>
- Create shared selectDeployedChange and selectDeployedPackage utilities
- Fix revert command to use scoped deployed packages when --package not supplied
- Add interactive --to flag functionality to verify command
- Both commands now use database-aware package selection with workspace fallback
- Follow established argv passthrough patterns to prevent duplicate prompts

Co-Authored-By: Dan Lynch <[email protected]>
@pyramation pyramation closed this Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants