-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrations rollback cmd #159
Conversation
- Added `saveRollbackData` function to capture original states of stories before modifications. - Improved error handling for migration function loading failures, ensuring all stories are marked as failed if the migration function cannot be loaded. - Refactored story processing logic to filter out stories without content and ensure valid stories are processed for each migration file. - Enhanced comments for clarity on the migration process and rollback functionality.
- Added `rollback` command to support rolling back migrations. - Introduced `restoreFromRollback` function to restore stories from rollback files. - Enhanced error handling and user feedback during the rollback process. - Updated migration index to include rollback actions and constants.
- Introduced unit tests for `saveRollbackData` and `readRollbackFile` functions to ensure correct behavior during rollback operations. - Refactored `restoreFromRollback` to `readRollbackFile` for clarity and improved error handling. - Enhanced the rollback command to read rollback data and restore stories, including handling various edge cases. - Updated test cases to cover scenarios such as successful rollbacks, error handling, and directory creation.
- Created a comprehensive README.md for the `rollback` command, outlining a detailed testing checklist. - Included sections on general requirements, required arguments, error handling, options, rollback process, examples, and file structure. - Documented the expected behavior and error messages for various scenarios to ensure clarity during testing.
- Fixed the JSON structure in `.vscode/launch.json` by properly closing the `env` object and ensuring correct formatting for the subsequent configuration object. - This change enhances the clarity and functionality of the launch configuration for debugging migrations.
@alvarosabu I cannot run migrations 🤔 Even providing a correct migration path, this is what I see in the console Migrations Rolling back migration undefined...
Error
▲ error Failed to rollback migration: Failed to read rollback file: The "path" argument must be of type string. Received undefined
ℹ For more information about the error, run the command with the `--verbose` flag This was the command I run (space masked) $ pnpm dev mig rollback --space ***** --path .storyblok/migrations/*****/rollbacks/simple_component.1742559178779.json Same error message with |
What is @edodusi did you follow the instructions in the readme? That's not a valid rollback command. Rollback always need a file name:
That's why is path is only if you generate the migration in a custom path before, not to pass the migration file you want to run |
@alvarosabu Ok sorry I misread, I found the Sorry, that works 😉 |
- Updated the `readRollbackFile` function to ensure the correct file path is used by appending `.json` if not already present, enhancing robustness in file reading. - Refactored the `handleMigrations` function to utilize `structuredClone` for creating a deep copy of the story content, improving performance and avoiding potential issues with JSON serialization.
Migrations Rollback Command
The
storyblok migrations rollback
command allows you to revert content migrations previously applied to your Storyblok stories. This is particularly useful when you need to undo changes made by a migration, restore content to its previous state, or recover from migration errors.Rollback files are automatically generated when running
storyblok migrations run
as of the introduction of this PRPrerequisites
Before rolling back migrations, ensure you have:
.storyblok/migrations/{spaceId}/rollbacks
directoryBasic Usage
Architecture & Flow
The rollback command is organized in three main layers with a specific processing flow to ensure safe and efficient content restoration.
Command Structure
Processing Flow Examples
1. Simple Rollback
Flow:
2. Custom Path Rollback
Flow:
Key Features
Safe Restoration
Flexible Configuration
Progress Tracking
Error Handling
Rollback File Structure
Rollback files are automatically generated during migrations and follow this structure:
File Organization
Testing Checklist
General Requirements
Required Arguments
[migrationFile]
-s, --space=TARGET_SPACE_ID
Error Handling
Options
--path=<path>
--verbose
Notes