# Update Process

IMPORTANT: Take a complete backup of your database and files before you update or run any of the commands on this page.

## Overview

This guide explains how to safely update WaDesk to a newer version. All PHP dependencies and frontend assets are pre-built in the update package, so a standard update is: back up → upload new files → run migrations → clear cache and rebuild assets → restart the Node bridge.

Always review the Change Log first to understand what has changed and whether a release needs new environment variables or configuration.

> Note: WaDesk is updated by replacing files on your server — there is no “update” button inside the app. Follow the steps below in order.

## Step 1: Back Up Your Database and Files

Never skip this step. Before touching anything, back up the two things that contain your data and configuration:

- Database: Export it via your hosting control panel (phpMyAdmin → Export) or over SSH:

      mysqldump -u your_db_user -p your_database > wadesk-backup.sql

- Files: Download or compress your whole WaDesk directory — or at minimum the items you must never lose: `.env`, the `storage/` folder, and any user uploads in `public/`.

> Keep these backups until you have confirmed the update works. If anything goes wrong, they are your fastest path back to a working install (see Rollback).

## Step 2: Upload the New Files

Download the latest version from your CodeCanyon Downloads page, then upload the new files into your WaDesk directory, overwriting the existing application code. You can use your hosting File Manager, FTP/SFTP, or over SSH:

    rsync -av --exclude='.env' --exclude='storage/' --exclude='node/node_modules/' /tmp/wadesk-update/ /var/www/wadesk/

Overwrite the application code — `app/`, `config/`, `database/migrations/`, `resources/`, `routes/`, `public/build/`, the `node/` bridge source, and root files such as `composer.json` and `config/version.php`.

> Assets are pre-built. The update package already contains the compiled Vite assets in `public/build/`, so for most updates you do not need to run `composer install` or `npm run build`. Only rebuild if the changelog says new dependencies were added (see Step 4).

## What NOT to Overwrite

These contain your data and configuration. Replacing them will break your install or lose your data. Always exclude them when uploading:

- `.env` — Your database credentials, app key, mail, AI, and payment-gateway keys. Losing this breaks the installation.
- `storage/` — Logs, cached files, sessions, and the bundled Node bridge's WhatsApp session/auth data. Overwriting this disconnects every Unofficial API number.
- User uploads in `public/` (e.g. uploaded media, logos, and branding assets) — never delete buyer-uploaded files.
- `vendor/` and `node/node_modules/` — Installed dependencies. Leave them in place unless the changelog tells you to reinstall.

> Critical: If your update tool cannot exclude folders, extract the package to a separate directory first and copy only the application code across — do not let `.env` or `storage/` be overwritten.

## Step 3: Run Database Migrations

New versions may add or change database tables. Run migrations so the schema matches the new code. Only new migrations run — your existing data is not touched.

VPS / Dedicated Server (SSH):

    php artisan migrate --force

Shared Hosting (no SSH): Use your hosting's “PHP / Cron” or terminal tool to run the same command in your application's root directory, or ask your hosting provider's support to run `php artisan migrate --force` for you.

> Do not skip migrations. Running new code against an old schema is the most common cause of post-update errors.

## Step 4: Clear Cache and Rebuild Assets

Stale config, route, view, and compiled caches can make new code misbehave. Clear and rebuild them.

VPS / Dedicated Server (SSH):

    php artisan optimize:clear
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache

Shared Hosting (no SSH): Using your File Manager, delete the contents of these folders (keep the folders themselves):

- `bootstrap/cache/` — delete all `.php` files
- `storage/framework/cache/data/` — delete all files
- `storage/framework/views/` — delete all `.php` files

Only if the changelog says new dependencies were added, reinstall and rebuild:

    composer install --no-dev --optimize-autoloader
    npm install
    npm run build

## Step 5: Restart the Node Bridge

If any workspace uses the Unofficial API engine, restart the bundled Node.js bridge so it runs the new code. Your saved WhatsApp sessions live in `storage/` and are not affected by a restart — connected numbers stay connected.

If you run the bridge under PM2:

    pm2 restart wadesk-bridge

If you run it under systemd:

    sudo systemctl restart wadesk-bridge

Then restart Laravel's queue workers so they pick up the new code as well:

    php artisan queue:restart

> Cloud API / Twilio only: If no workspace uses the Unofficial API, you can skip the bridge restart — but still run `queue:restart`.

## Step 6: Verify

Confirm the update succeeded by checking the core flows:

- The admin panel and a workspace dashboard both load without errors.
- Connected WhatsApp numbers still show as connected (Unofficial API), or your Cloud API / Twilio sender still sends.
- A test message sends and inbound messages arrive in the Team Inbox.
- Queue jobs are processing (campaigns, scheduled sends).
- The version shown in the admin panel matches the new release.

> Never run a real campaign as your test. Use a single test number you control — live workspaces send real WhatsApp messages.

## Rollback

If the update causes problems and you need to revert to the previous version:

1. Restore the database:

       mysql -u your_db_user -p your_database < wadesk-backup.sql

2. Restore files: Replace the updated application code with your backed-up copy. Your `.env` and `storage/` were never touched, so leave them as they are.
3. Clear caches:

       php artisan optimize:clear

4. Restart the bridge and queue:

       pm2 restart wadesk-bridge
       php artisan queue:restart

Keep your backup until the new version has been verified in production for a few days.

## Important Notes

> Critical: Follow these guidelines to avoid data loss and downtime.

- Never delete or overwrite `.env` — it holds your app key, database credentials, and all API/payment keys.
- Never delete or overwrite `storage/` — it holds logs, sessions, and the Node bridge's WhatsApp auth data for every connected number.
- Always run migrations after uploading new files.
- Always clear caches — stale config/route/view caches are a frequent source of post-update bugs.
- Restart the Node bridge and queue workers so long-running processes pick up the new code.
- Check the changelog for breaking changes — some releases require new environment variables or a dependency reinstall. Review the Change Log before every update.