Updating MJ Bot
Follow this guide whenever a new version of MJ Bot is released. The update process covers the bot, the dashboard, and the database schema.
Always back up your database before updating. If a migration fails, you will need a backup to restore your data.
Step 1: Pull the Latest Code
Navigate to the MJ Bot root directory and pull the latest changes:
cd /home/mjbot
git pull
If you have local changes that conflict with the update, stash them first:
git stash
git pull
git stash pop
Step 2: Install New Dependencies
Install any new or updated packages for both the bot and the dashboard:
# Bot
npm install
# Dashboard
cd dashboard
npm install
Step 3: Run Database Migrations
Apply any schema changes to your database using Prisma:
# Bot
npx prisma db push
# Dashboard
cd dashboard
npx prisma db push
prisma db push synchronizes your database schema with the Prisma schema file without creating migration files. This is safe for most updates. If the update includes breaking schema changes, the release notes will provide specific instructions.
Step 4: Rebuild
Build the production bundles for both the bot and the dashboard:
# Bot
npm run build
# Dashboard
cd dashboard
npm run build
Step 5: Restart
Restart both processes with pm2:
pm2 restart mj-bot mj-dashboard
Step 6: Verify
Confirm that both processes are running:
pm2 status
Check the logs to make sure there are no errors:
pm2 logs mj-bot --lines 20
pm2 logs mj-dashboard --lines 20
After updating, test a few bot commands and log in to the dashboard to confirm everything is working correctly.
Quick Reference
Here is the full update process as a single command sequence:
cd /home/mjbot && \
git pull && \
npm install && \
npx prisma db push && \
npm run build && \
cd dashboard && \
npm install && \
npx prisma db push && \
npm run build && \
cd .. && \
pm2 restart mj-bot mj-dashboard && \
pm2 status
Do not skip the build step. Running pm2 restart without rebuilding will start the old version of the code.