In case there has been an error during a Motion V2 automated update, you will need to launch the database migration procedure manually.


Follow these steps:


Check which migrations you are missing. There are two possible ways of having missing migrations:

  • The system launched the migrations, but for some reasons they have not been completed.
  • The system writes in the migrations database table after each migration/update is launched, after the update, to keep track of which updates have been completed and just use the missing ones. We need to understand what migrations did not work well, for example if you are missing a field in a table that should be there because you ran a migration containing the query where you add it.


You can check the contents of the migrations files, divided by version, in the /var/opt/motion2/server/migrations folder.
Once you have found out which migration you need to re-run, you'll need to go in the migrations database table and delete all rows starting from the last one, until the migration version you need (include that in the deleted rows).


Example:


Log into your mysql instance on the xCally server:


mysql -u root -p 


Type the following:


mysql> USE motion2


Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


mysql> select * from migrations;

+----+-----------+---------------------+---------------------+

| id | version   | createdAt           | updatedAt           |

+----+-----------+---------------------+---------------------+

|  1 | 2.3.6.js  | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  2 | 2.3.7.js  | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  3 | 2.3.8.js  | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  4 | 2.3.9.js  | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  5 | 2.3.91.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  6 | 2.3.92.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  7 | 2.3.93.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  8 | 2.3.94.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

|  9 | 2.3.95.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

| 10 | 2.3.96.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

| 11 | 2.3.97.js | 2020-10-12 15:30:27 | 2020-10-12 15:30:27 |

| 12 | 2.3.98.js | 2020-10-12 15:30:28 | 2020-10-12 15:30:28 |

+----+-----------+---------------------+---------------------+

12 rows in set (0.10 sec)


If you need to re-run the migrations for the 2.3.91 version, you'll need to delete those selected rows (shown in red).



The system did not launch the migrations at all:


In this case the database will not contain the versions migrations rows, so you don't need to delete rows. You still need to access the migrations database table though, to read the version number of the last executed version, so you know where to start from when you launch them. Now that you know from which migration version to start from, you'll need to tell the application, modifying its package version. Authenticate in your server ssh console as root user and navigate to the /var/opt/motion2/ folder


cd /var/opt/motion2


Edit the package.json and change the version with the one previous the one you want to run again. E.g. If you want to run migrations starting from 2.3.91, you'll need to insert 2.3.9 as version


[root@thinkdigital motion2]# vi package.json

{

  "name": "motion",

  "version": "2.3.9",

  "description": "xCALLY Motion is the new Realtime asynchronous solution for your multichannel contact center over Asterisk.",

  "main": "server/app.js",

  "engines": {

    "node": "6.10.3"

  },

 

Save the package.json, authenticate yourself as motion user in the ssh console


su motion


and restart the motion2 service


pm2 restart motion2


Call the migration API to launch all the missing migrations (starting from the one you need, which is the one after the version you set in the package.json file):


curl --insecure https://localhost/api/version/migrations -v -u 'username:password'  


(Replace username/password with GUI admin credentials from your instance)


Migrations will run in sequence from the version you stipulated above until the currently installed xCally motion version.


Check that all the migrations have been performed, looking in the migrations database table for the latest inserted row to be the same as the latest migration available in the /var/opt/motion2/server/migrations. Go back and edit the /var/opt/motion2/package.json file and set the version to the latest one. Save the file, authenticate as motion user in your ssh console and restart the motion2 service again.

su motion

pm2 restart motion2


and check that everything should now be working fine.