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

174 lines
3.3 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 than require rebuild it.
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
### Custom controllers and services
If you are using [core services](../guides/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.
**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);
},
};
```
The same modification was made to `strapi.query()`. Read more about **Queries** [here](../guides/queries.md).
2019-09-06 11:36:46 +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](../guides/queries.html#api-reference).
2019-09-06 11:36:46 +02:00
### Bootstrap function
The function exported in `config/functions/bootstrap.js` previsouly 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.
**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();
};
```
### Custom hooks
If you have custom [hooks](../advanced/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();
},
};
```