strapi/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.15-to-beta.16.md

218 lines
4.0 KiB
Markdown
Raw Normal View History

2019-09-06 11:36:46 +02:00
# Migration guide from beta.15 to beta.16
Upgrading your Strapi application to `v3.0.0-beta.16`.
## Upgrading your dependencies
Start by upgrading all your strapi package version to `3.0.0-beta.16`.
Your package.json would look like this:
```json
{
//...
"dependencies": {
"strapi": "3.0.0-beta.16",
"strapi-admin": "3.0.0-beta.16",
"strapi-hook-bookshelf": "3.0.0-beta.16",
"strapi-hook-knex": "3.0.0-beta.16",
"strapi-plugin-content-manager": "3.0.0-beta.16",
"strapi-plugin-content-type-builder": "3.0.0-beta.16",
"strapi-plugin-email": "3.0.0-beta.16",
"strapi-plugin-graphql": "3.0.0-beta.16",
"strapi-plugin-settings-manager": "3.0.0-beta.16",
"strapi-plugin-upload": "3.0.0-beta.16",
"strapi-plugin-users-permissions": "3.0.0-beta.16",
"strapi-utils": "3.0.0-beta.16"
}
}
```
Then run either `yarn install` or `npm install`.
## Building your administration panel
This new release introduces changes to the administration panel that require a rebuild.
Start by deleting your current build:
```bash
rm -rf ./build
```
Build the administration panel:
```bash
yarn build
# or
npm run build
```
2019-09-06 11:36:46 +02:00
## Updating your code
2019-09-09 12:24:24 +02:00
### Wysiwyg
Wysiwyg was previously an option of the `text` type that was stored in the database. When deploying to production for the first time you had to re-select the option in the interface.
2019-09-09 12:24:24 +02:00
To make sure a Wysiwyg field stays the same when deploying, we introduced the `richtext` type. This type is equivalent to the previous `text` type with `wysiwyg` option enabled.
2019-09-09 12:24:24 +02:00
**Before**:
```json
{
//...
"attributes": {
"name": {
"type": "string"
}
"description": {
"type": "text"
}
}
}
```
**After**:
```json
{
//...
"attributes": {
"name": {
"type": "string"
}
"description": {
"type": "richtext"
}
}
}
```
2019-09-06 11:36:46 +02:00
### Custom controllers and services
2019-10-23 10:11:53 +02:00
If you are using [core services](../concepts/services.md), you previously needed to call `result.toJSON()` or `result.toObject()` to get a plain javascript object. This is not the case anymore, you will now receive a simple object directly.
2019-09-06 11:36:46 +02:00
**Before**:
```js
module.exports = {
async findOne(id) {
const result = await strapi.services.restaurant.findOne(id);
return result.toJSON();
},
};
```
**After**:
```js
module.exports = {
findOne(id) {
return strapi.services.restaurant.findOne(id);
},
};
```
2019-10-23 10:11:53 +02:00
The same modification was made to `strapi.query()`. Read more about **Queries** [here](../concepts/queries.md).
2019-09-06 11:36:46 +02:00
2019-10-23 10:11:53 +02:00
Keep in mind that if you are running custom ORM queries with Bookshelf or Mongoose you will still have to call `toJSON` or `toObject`. Check out this section about [custom queries](../concepts/queries.md#api-reference).
2019-09-06 11:36:46 +02:00
### Bootstrap function
The function exported in `config/functions/bootstrap.js` previously received a callback. This is not the case anymore. You can either use an async function, return a promise or simply run a synchronous function.
2019-09-06 11:36:46 +02:00
**Before**
```js
module.exports = {
defaults: {},
initialize(cb) {
// code
cb();
},
};
```
**After**
2019-09-06 11:36:46 +02:00
**Async**
```js
module.exports = async () => {
await someOperation();
};
```
**Promise**
```js
module.exports = () => {
return new Promise(/* ... */);
};
```
**Sync**
```js
module.exports = () => {
someSyncCode();
};
```
**No Function**
```js
module.exports = () => {};
```
2019-09-06 11:36:46 +02:00
### Custom hooks
2019-10-23 10:11:53 +02:00
If you have custom [hooks](../concepts/hooks.md) in your project, the `initialize` function will not receive a callback anymore. You can either use an async function, return a promise or simply run a synchronous function.
**Before**
```js
module.exports = {
defaults: {},
initialize(cb) {
// code
cb();
},
};
```
**After**
2019-09-06 11:36:46 +02:00
**Async**
```js
module.exports = {
defaults: {},
async initialize() {
await someOperation();
},
};
```
**Promise**
```js
module.exports = {
defaults: {},
initialize() {
return new Promise(/* ... */);
},
};
```
**Sync**
```js
module.exports = {
defaults: {},
initialize() {
someSyncCode();
},
};
```