Rollback & Undo
Nuxt Crouton includes a comprehensive rollback system to safely remove generated collections. This is useful when you need to:
- Remove a collection you no longer need
- Clean up after testing or experimentation
- Regenerate a collection from scratch
- Remove an entire layer
Single Collection Rollback
Remove a specific collection and all its generated files:
crouton-rollback shop products
This removes:
- Components (List.vue, Form.vue, Table.vue)
- Composables (useProducts.ts)
- Types (products.ts)
- API endpoints (if generated)
- Database schema (if generated)
- Config entries (app.config.ts)
Preview Before Removing
Use --dry-run to see what would be removed:
crouton-rollback shop products --dry-run
# Output:
📋 Preview: Would remove the following:
layers/shop/components/products/
├── List.vue
├── Form.vue
└── Table.vue
layers/shop/composables/
└── useProducts.ts
layers/shop/types/
└── products.ts
Total: 5 files
Proceed? (y/n)
Keep Files, Clean Config Only
Remove config entries but keep generated files:
crouton-rollback shop products --keep-files
Useful when you want to keep customized components but remove them from the collection registry.
Skip Confirmation
For scripts or automation:
crouton-rollback shop products --force
Bulk Rollback
Remove multiple collections at once.
Remove Entire Layer
crouton-rollback-bulk --layer=shop
# Output:
⚠️ This will remove ALL collections in the 'shop' layer:
- products (5 files)
- categories (5 files)
- orders (5 files)
Total: 15 files
Continue? (y/n)
Remove All Collections from Config
crouton-rollback-bulk --config=./crouton.config.js
# Reads the config file and removes all collections defined in it
Bulk Rollback Options
Same options as single rollback:
# Preview bulk changes
crouton-rollback-bulk --layer=shop --dry-run
# Keep files, clean config
crouton-rollback-bulk --layer=shop --keep-files
# Skip confirmation
crouton-rollback-bulk --layer=shop --force
Interactive Rollback
Launch an interactive UI to select collections:
crouton-rollback-interactive
Interactive UI:
? Select collections to remove:
◯ shop/products (5 files)
◯ shop/categories (5 files)
◉ shop/orders (5 files)
◯ blog/posts (5 files)
Use arrow keys to navigate, space to select, enter to confirm
Options:
# Preview mode
crouton-rollback-interactive --dry-run
# Keep files
crouton-rollback-interactive --keep-files
What Gets Removed
The rollback system removes:
✅ Always Removed
- Generated component files
- Generated composable files
- Generated type files
- Config registry entries (app.config.ts)
⚠️ Conditionally Removed
- Database schema files (unless
--keep-files) - API endpoints (unless
--keep-files) - Layer directory (if empty after removal)
❌ Never Removed
- Custom modifications you made
- Non-generated files in the collection directory
- Database data (only schema definitions)
- Git history
Safe Rollback Workflow
Best practices for safe rollbacks:
1. Always Preview First
crouton-rollback shop products --dry-run
2. Check Git Status
git status
# Verify you have no uncommitted changes
3. Run Rollback
crouton-rollback shop products
4. Verify Changes
git status
git diff
# Review what was removed
5. Commit or Revert
# If correct:
git add .
git commit -m "Remove products collection"
# If wrong:
git restore .
Common Scenarios
Regenerate a Collection from Scratch
# 1. Remove the old collection
crouton-rollback shop products --force
# 2. Regenerate with updated schema
crouton-generate shop products --fields-file=product-schema.json
Remove Test Collections
# Remove all test collections at once
crouton-rollback-interactive
# Select all test collections in the UI
Clean Up Before Deployment
# Remove unused layer
crouton-rollback-bulk --layer=experiments --force
Preserve Customizations
# Keep customized files, just remove from registry
crouton-rollback shop products --keep-files
Troubleshooting
"Collection not found"
The collection may already be removed or was never generated:
# Check what collections exist
ls layers/*/components/
"Permission denied"
Files may be in use:
# Stop your dev server first
# Then try rollback again
"Config entry not found"
The collection isn't registered in app.config.ts. This is safe to ignore, or you can manually verify:
// app.config.ts
export default defineAppConfig({
croutonCollections: {
// Check if collection exists here
}
})
Accidental Removal
Restore from Git:
git restore layers/shop/components/products/
git restore layers/shop/composables/useProducts.ts
# etc.
Best Practices
✅ DO:
- Use
--dry-runfor preview before every rollback - Commit your work before running rollback commands
- Verify changes with
git statusafter rollback - Use interactive mode when unsure which collections to remove
- Document why you're removing collections (in commit messages)
❌ DON'T:
- Run bulk rollback without preview
- Use
--forcewithout reviewing what will be removed - Forget to restart your dev server after rollback
- Remove collections that other parts of your app depend on
- Use rollback as a replacement for proper version control
Related Sections
- Generator Commands - Creating collections
- Troubleshooting - Common issues
- Best Practices - Development workflow