TonyDeplanque / strapi-plugin-migrations

Init or update your data easly with a version controller.
25 stars 14 forks source link

fix: ensure that files on migrations folder match format before using them #13

Open ReyRod opened 1 year ago

ReyRod commented 1 year ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch strapi-plugin-migrations@1.0.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/strapi-plugin-migrations/server/services/migrations.js b/node_modules/strapi-plugin-migrations/server/services/migrations.js
index 5a8dc1c..7b301f8 100644
--- a/node_modules/strapi-plugin-migrations/server/services/migrations.js
+++ b/node_modules/strapi-plugin-migrations/server/services/migrations.js
@@ -84,7 +84,8 @@ module.exports = ({ strapi }) => ({

   getVersionFromFile(filename) {
     const regex = this.getFileRegex()
-    return filename.match(regex)[1] ? Number(filename.match(regex)[1]) : 0
+    const matches = filename.match(regex);
+    return matches && matches[1] ? Number(filename.match(regex)[1]) : 0
   },

   checkIfTheFileNameIsAutorized(file) {

This issue body was partially generated by patch-package.

https://github.com/TonyDeplanque/strapi-plugin-migrations/pull/11

markhughes commented 1 year ago

Looks like my PR got merged, so hopefully fixes your issue too!