Skip to content
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

Add migration path option and find stories for renamed components #91

Open
dylanschoenmakers opened this issue Apr 23, 2024 · 1 comment
Labels
feature [Issue] New feature or request pending-triage [Issue] Ticket is pending to be prioritised PR welcome [Contribution] Pull requests are welcome.

Comments

@dylanschoenmakers
Copy link

Hi,

We are having a problem with renaming of stories where the contains_component query does not work for us. We solved it with this patch for now, is this a known issue?

Here is the diff that solved my problem:

diff --git a/node_modules/storyblok/src/cli.js b/node_modules/storyblok/src/cli.js
index 5b50343..a4adebd 100755
--- a/node_modules/storyblok/src/cli.js
+++ b/node_modules/storyblok/src/cli.js
@@ -383,12 +383,14 @@ program
   .option('--dryrun', 'Do not update the story content')
   .option('--publish <PUBLISH_OPTION>', 'Publish the content. It can be: all, published or published-with-changes')
   .option('--publish-languages <LANGUAGES>', 'Publish specific languages')
+  .option('--migration-path <MIGRATION_PATH>', 'Path to the migration file')
   .action(async (options) => {
     const field = options.field || ''
     const component = options.component || ''
     const isDryrun = !!options.dryrun
     const publish = options.publish || null
     const publishLanguages = options.publishLanguages || ''
+    const migrationPath = options.migrationPath || ''
 
     const space = program.space
     if (!space) {
@@ -418,7 +420,7 @@ program
         api,
         component,
         field,
-        { isDryrun, publish, publishLanguages }
+        { isDryrun, publish, publishLanguages, migrationPath }
       )
     } catch (e) {
       console.log(chalk.red('X') + ' An error ocurred when run the migration file: ' + e.message)
diff --git a/node_modules/storyblok/src/tasks/migrations/utils.js b/node_modules/storyblok/src/tasks/migrations/utils.js
index 3839f77..84755c9 100644
--- a/node_modules/storyblok/src/tasks/migrations/utils.js
+++ b/node_modules/storyblok/src/tasks/migrations/utils.js
@@ -1,5 +1,5 @@
 const onChange = require('on-change')
-const { isArray, isPlainObject, has, isEmpty, template, truncate } = require('lodash')
+const { isArray, isPlainObject, has, isEmpty, template, truncate, filter } = require('lodash')
 const fs = require('fs-extra')
 const chalk = require('chalk')
 
@@ -49,7 +49,11 @@ const getNameOfMigrationFile = (component, field) => {
 const getStoriesByComponent = async (api, componentName) => {
   try {
     const stories = await api.getStories({
-      contain_component: componentName
+      filter_query: {
+        component: {
+          like: componentName
+        }
+      }
     })
 
     return stories

This issue body was partially generated by patch-package.

@alvarosabu alvarosabu added feature [Issue] New feature or request pending-triage [Issue] Ticket is pending to be prioritised PR welcome [Contribution] Pull requests are welcome. labels Sep 17, 2024
@alvarosabu
Copy link
Contributor

Hi @dylanschoenmakers we didn't have this use-case before but make sense to me, since you already worked on the feature, would you like to help us with a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature [Issue] New feature or request pending-triage [Issue] Ticket is pending to be prioritised PR welcome [Contribution] Pull requests are welcome.
Projects
None yet
Development

No branches or pull requests

2 participants