-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Add migration script and guide #8790
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
Merged
alexandrebodin
merged 5 commits into
feature/relational-fields
from
rf/eng-127/migration-script-rf
Dec 11, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
docs/.vuepress/public/assets/migrations/scripts/migrate-3.4.0.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
|
|
||
| const ONE_RELATIONS = ['oneToOne', 'manyToOne', 'oneWay']; | ||
|
|
||
| const createStrapiApp = async projectPath => { | ||
| if (!projectPath) { | ||
| throw new Error(` | ||
| -> Path to strapi project is missing. | ||
| -> Usage: node migrate-3.4.0.js [path]`); | ||
| } | ||
|
|
||
| let strapi; | ||
| let app; | ||
| try { | ||
| strapi = require(require.resolve('strapi', { paths: [projectPath] })); | ||
| const pkgJSON = require(path.resolve(projectPath, 'package.json')); | ||
| if (!pkgJSON || !pkgJSON.dependencies || !pkgJSON.dependencies.strapi) { | ||
| throw new Error(); | ||
| } | ||
| } catch (e) { | ||
| throw new Error(` | ||
| -> Strapi lib couldn\'t be found. Are the node_modules installed? | ||
| -> Fix: yarn install or npm install`); | ||
| } | ||
|
|
||
| try { | ||
| app = await strapi({ dir: projectPath }).load(); | ||
| } catch (e) { | ||
| throw new Error(` | ||
| -> The migration couldn't be procceed because Strapi app couldn't start. | ||
| -> ${e.message}`); | ||
| } | ||
|
|
||
| return app; | ||
| }; | ||
|
|
||
| const isSortableRFAssoc = a => | ||
| ONE_RELATIONS.includes(a.nature) && !['created_by', 'updated_by'].includes(a.alias); | ||
|
|
||
| const run = async () => { | ||
| const projectPath = process.argv[2]; | ||
| const app = await createStrapiApp(projectPath); | ||
|
|
||
| const contentTypeService = app.plugins['content-manager'].services['content-types']; | ||
|
|
||
| for (const uid of Object.keys(app.contentTypes)) { | ||
| const modelDef = app.getModel(uid); | ||
| const manyRelationFields = modelDef.associations.filter(isSortableRFAssoc); | ||
| if (manyRelationFields.length) { | ||
| const conf = await contentTypeService.findConfiguration({ uid }); | ||
| manyRelationFields.forEach(assoc => { | ||
| try { | ||
| conf.metadatas[assoc.alias].list.sortable = true; | ||
| } catch (e) { | ||
| // silence | ||
| } | ||
| }); | ||
| await contentTypeService.updateConfiguration({ uid }, conf); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| run() | ||
| .catch(e => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }) | ||
| .then(() => { | ||
| console.log('Migration successfully finished! 🎉'); | ||
| process.exit(0); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
docs/v3.x/migration-guide/migration-guide-3.3.x-to-3.4.0.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Migration guide from 3.3.x to 3.4.0 | ||
|
|
||
| **Make sure your server is not running until the end of the migration** | ||
|
|
||
| :::warning | ||
| If you are using **extensions** to create custom code or modifying existing code, you will need to update your code and compare your version to the new changes on the repository. | ||
| <br> | ||
| Not updating your **extensions** can break your app in unexpected ways that we cannot predict. | ||
| ::: | ||
|
|
||
| ## Migration | ||
|
|
||
| 1. First, update your app as usual by following the basic [version update guide](../guides/update-version.md) and then come back here | ||
| 2. Download this script: <a :href="$withBase('/assets/migrations/scripts/migrate-3.4.0.js')" download>migrate-3.4.0.js</a> | ||
petersg83 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 3. Execute it with the following command: `node migrate-3.4.0.js [path-to-your-project]` | ||
petersg83 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 4. Delete the script (optional) | ||
|
|
||
| 🎉 Congrats, your application has been migrated! | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.