Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/.vuepress/public/assets/migrations/scripts/migrate-3.4.0.js
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);
});
1 change: 1 addition & 0 deletions docs/v3.x/migration-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If you were upgrading from the `3.0.0-beta.19.5` to `3.2.0`, here are the follow

## V3 guides

- [Migration guide from 3.3.x to 3.4.0](migration-guide-3.3.x-to-3.4.0.md)
- [Migration guide from 3.2.5 to 3.3.0](migration-guide-3.2.5-to-3.3.0.md)
- [Migration guide from 3.2.3 to 3.2.4](migration-guide-3.2.3-to-3.2.4.md)
- [Migration guide from 3.1.x to 3.2.3](migration-guide-3.1.x-to-3.2.x.md)
Expand Down
18 changes: 18 additions & 0 deletions docs/v3.x/migration-guide/migration-guide-3.3.x-to-3.4.0.md
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>
3. Execute it with the following command: `node migrate-3.4.0.js [path-to-your-project]`
4. Delete the script (optional)

🎉 Congrats, your application has been migrated!