v4.1.8+ to v4.1.10 migration guide
The Strapi v4.1.8+ to v4.1.10 migration guide upgrades versions of v4.1.8 and above to v4.1.10. This migration guide is needed only for users who experienced missing MIME types on their media when uploading media through the Content API (see GitHub issue #12761). The migration to 4.1.10 consists of 3 steps:
- Upgrading the application dependencies
- Installing database migration script (optional)
- Reinitializing the application
Plugins extension that create custom code or modify existing code, will need to be updated and compared to the changes in the repository. Not updating the plugin extensions could break the application.
Upgrading the application dependencies to 4.1.10
Stop the server before starting the upgrade.
- Upgrade all of the Strapi packages in the
package.json
to4.1.10
:
{
// ...
"dependencies": {
"@strapi/strapi": "4.1.10",
"@strapi/plugin-users-permissions": "4.1.10",
"@strapi/plugin-i18n": "4.1.10",
// ...
}
}
Save the edited
package.json
file.Install the upgraded version:
- yarn
- npm
yarn
npm install
💡 TipIf the operation doesn't work, try removing your
yarn.lock
orpackage-lock.json
. If that doesn't help, remove thenode_modules
folder as well and try again.
Installing database migration script (optional)
This step is only required if some files in your database have their MIME type set to null
(see GitHub issue #12761).
To make sure Strapi can load the Media Library, the following migration script file must be added to ./database/migrations
. The script automatically sets MIME types for files that miss one, based on their filename. The script will be automatically executed only once at the next launch of Strapi.
To add the script:
- In the
./database/migrations
folder, create a file named2022.05.10T00.00.00.fill-files-mime-type.js
. - Copy and paste the following code into the previously created file:
'use strict'
const mimeTypes = require('mime-types');
const BATCH_SIZE = 1000;
const FILE_TABLE = 'files';
async function up(trx) {
let lastId = 0;
while (true) {
const files = await trx
.select(['id', 'name'])
.from(FILE_TABLE)
.where('mime', null)
.andWhere('id', '>', lastId)
.orderBy('id', 'asc')
.limit(BATCH_SIZE);
const mimesMap = {};
for (let file of files) {
const mime = mimeTypes.lookup(file.name) || 'application/octet-stream';
mimesMap[mime] = mimesMap[mime] || [];
mimesMap[mime].push(file.id);
}
for (let mime of Object.keys(mimesMap)) {
await trx.update({ mime }).from(FILE_TABLE).whereIn('id', mimesMap[mime]);
}
if (files.length < BATCH_SIZE) {
break;
}
lastId = files[files.length - 1].id;
}
}
async function down() {}
module.exports = { up, down };
Rebuild the application
Run the following command in your project root directory to rebuild Strapi's admin panel:
- yarn
- npm
yarn build
npm run build
Restart the application
Run the following command in your project root directory to restart the application:
- yarn
- npm
yarn develop
npm run develop