-
Notifications
You must be signed in to change notification settings - Fork 31
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 run cmd #155
base: next
Are you sure you want to change the base?
Conversation
- Introduced new migrations command with generate subcommand - Added constants for migrations command and color palette - Implemented migration file generation for specific component fields - Created actions and tests for migration file creation - Updated index to import migrations command and related modules
…migrations commands
- Added comprehensive test cases for migrations generate command - Implemented tests for successful migration generation with and without custom path - Added error handling tests for missing component name, field, and non-existent components - Updated test file to improve error checking and mock session state
- Created detailed documentation for migrations generate command - Included usage examples, command options, and output structure - Added manual testing checklist and best practices - Provided insights into migration file generation and usage scenarios
- Enhanced migration generation to support optional file name suffix - Updated `generateMigration` function to accept optional suffix parameter - Modified command options to include `--suffix` flag - Updated README with new suffix generation example and documentation - Adjusted file name generation logic to incorporate optional suffix
…rameter - Modified test cases to include optional suffix parameter in `generateMigration` function calls - Ensured test coverage reflects the recent enhancement of migration file generation
- Removed required field parameter from migration generation - Updated migration template with more generic examples - Simplified file naming convention for migration files - Removed unnecessary field-specific logic from generate command - Updated tests to reflect new migration generation approach
- Created comand-less story module - Implemented `objectToStringParams` utility function in `utils/index.ts` - Converts object values to strings for use with URLSearchParams
- Created `createRegexFromGlob` utility function in `utils/index.ts` - Moved regex creation logic from `filterSpaceDataByPattern` to new utility function - Simplified pattern matching with a reusable glob-to-regex conversion method
…upport - Implemented new migrations run command with advanced migration processing - Added support for running migrations on specific components or entire spaces - Created utility functions for reading and applying migration files - Introduced dynamic migration function loading and content transformation - Implemented dry-run mode and detailed migration result reporting - Added new actions for fetching and updating stories - Enhanced error handling and logging for migration operations
…spinner management - Added filtering of migrations based on component name - Optimized spinner usage and logging for migration operations - Simplified migration processing logic - Enhanced error handling and migration result tracking - Moved spinner initialization to more precise locations in the code
- Enhanced code readability by adding multi-line conditionals in migration and utility files - Updated JSDoc comments in `operations.ts` with more detailed parameter descriptions - Refined logging output formatting in migration result summary - Minor improvements to code structure and error reporting
- Updated MSW handlers to use dynamic space ID and simplified mock logic - Improved error handling and test coverage for fetchStories method - Removed redundant handler and consolidated API mocking - Updated test cases to handle async errors more robustly - Simplified error catching and assertion in test scenarios - Removed unnecessary return statement in updateStory action
- Created test file for migration file reading actions - Added test cases for `readJavascriptFile` method covering successful reads, error scenarios, and file validation - Implemented tests for `readMigrationFiles` method with various scenarios including file filtering, empty directories, and error handling - Used memfs for virtual file system testing to simulate different file system conditions
- Implemented tests for `getMigrationFunction` method - Added test cases covering successful migration function loading - Tested scenarios for missing default exports and non-existent files - Used memfs and vi.doMock for simulating dynamic module imports - Ensured robust error handling and function validation
- Implemented detailed test suite for migrations run command - Added test cases for running migrations with and without component filtering - Mocked session, stories actions, and migration operations - Verified correct method calls and migration processing logic - Ensured comprehensive coverage of migration run scenarios
- Added comprehensive test cases for migrations run command - Implemented tests for migration filtering, dry run mode, and handling of migration results - Verified correct behavior when no stories are modified - Added mock scenarios for different migration outcomes - Expanded test suite to cover edge cases in migration processing
- Introduced new `--query` option for filtering stories using Storyblok filter query syntax - Updated `MigrationsRunOptions` interface to include optional query parameter - Modified `fetchStoriesByComponent` method to handle filter query parameters - Added CLI option for query-based story filtering in migrations run command - Enhanced `fetchStories` method to support complex filter query parsing - Updated `StoriesQueryParams` interface to allow flexible filter query handling
- Modified test cases in `migrations/run/index.test.ts` to accommodate new `fetchStoriesByComponent` method signature - Updated `stories/actions.test.ts` to expect two stories instead of one in a specific test scenario - Adjusted method call expectations to include optional parameters - Ensured test coverage reflects recent changes in method signatures
- Introduced new `--starts-with` option for filtering stories by path - Updated `MigrationsRunOptions` interface to include optional `startsWith` parameter - Modified `fetchStoriesByComponent` method to handle `starts_with` filter - Enhanced `StoriesFilterOptions` interface to support path-based filtering - Added CLI option for path-based story filtering in migrations run command - Updated test cases to cover new `starts-with` filter functionality - Improved logging to display applied filters in story fetching process
…erations - Deleted unnecessary `storyModified` variable that was not being used - Simplified code by removing redundant variable declaration - Maintained existing logic for migration content processing
- Introduced new `--publish` option with modes: 'all', 'published', and 'published-with-changes' - Updated `MigrationsRunOptions` interface to include optional `publish` parameter - Added utility functions `isStoryPublishedWithoutChanges` and `isStoryWithUnpublishedChanges` - Modified `updateStory` action to support optional publish flag - Enhanced migration run command to handle different publication scenarios - Updated test cases to cover new publish option functionality - Improved story update logic with flexible publishing options
- Created detailed README.md for migrations run command - Documented test scenarios for various command options and behaviors - Included examples of command usage with different flags - Provided notes on migration file structure and best practices - Outlined comprehensive testing requirements for command functionality
…tion - Removed unused imports from `index.test.ts` - Enhanced JSDoc for `updateStory` function in `actions.ts` - Removed unused `StoryContent` type import - Clarified parameters and added more descriptive documentation for story update method
@alvarosabu what do you think if we add an extra-confirmation after the run command? I imagine something like: $ pnpm dev mig run simple_component --space 325977
Storyblok CLI
✔ Found 1 migration files.
✔ Fetched 1 story with related content (filtered by component "simple_component").
Migration "simple-component.js" will be run. This will potentially alter the content of 1 story in your space. Are you sure you want to proceed?
> Yes/No
Success
✔ Successfully applied 1 migrations to 1 stories
✔ No failures reported
✔ Found 1 stories to update.
✔ Updated story Home - Completed in 182.05ms
Success
✔ Successfully updated 1 stories in Storyblok. Stopping at the first question. This is because this command changes content and to me it should require an extra-step, but I don't know if I'm too conservative. What do you think? |
@alvarosabu every other tests passed 👍 |
That is a good point, mm, considering the client's feedback they actually use the cli migration command as part of their CIs and scripts, so adding a prompt would interfere with that being autonomous. There is also a plan to add interactive or wizard mode in the future. I would say it's ok because the content migration is done by default as a save functionality on the Product, so they could always rollback there or rollback using the |
Migrations Run Command
The
storyblok migrations run
command allows you to execute content migrations on your Storyblok stories. This is particularly useful for batch updating content, transforming field values, or restructuring content across multiple stories in a space.Prerequisites
Before running migrations, ensure you have:
.storyblok/migrations/{spaceId}
directoryBasic Usage
Architecture & Flow
The migrations command is organized in three main layers with a specific processing flow to ensure safe and efficient content updates.
Command Structure
Processing Flow Examples
1. Simple Migration Run
Flow:
2. Component-Specific Migration
Flow:
3. Publication Control
Flow:
4. Story Filtering by Path
storyblok migrations run --space 12345 --starts-with "/en/blog/"
Flow:
5. Story Filtering by Query
storyblok migrations run --space 12345 --query "[highlighted][in]=true"
Flow:
Key Features
Selective Migration
Safe Execution
Publication Control
Content Filtering
Migration File Structure
Migration files should follow this structure:
Testing Strategy
The command includes comprehensive test coverage:
Testing checklist
Running migrations
storyblok migrations run
General
You are currently not logged in. Please login first to get your user info.
Required Arguments
[componentName]
(optional)-s, --space=TARGET_SPACE_ID
.storyblok/migrations/<TARGET_SPACE_ID>/
Error handling
Please provide the space as argument --space YOUR_SPACE_ID.
Options
--filter, --fi=<pattern>
*.amount.js
to run specific migrations--dry-run, -d
--query, -q=<query>
--query="[highlighted][in]=true"
--starts-with=<path>
--starts-with="/en/blog/"
--publish=<mode>
Supports different publication modes:
all
: Should publish all stories after migrationpublished
: Should only publish stories that were already publishedpublished-with-changes
: Should only publish stories that have unpublished changes after migrationMigration Results