# 🔄 ProjectWorlds Multi-School ERP SAAS - Official Update Guide

This guide is for users who already have the platform installed and want to seamlessly upgrade to the latest version **without losing any databases, user data, or uploaded media**.

> [!WARNING]
> **Extremely Important**: If you carelessly overwrite your `.env` file or `storage/` folder during an update, you will permanently lose your database connection and all uploaded school logos/attachments. Carefully follow the instructions below!

---

## 🛠️ Step-by-Step Safest Update Method

### Step 1: Backup Everything (Crucial)
1. Go into your aaPanel or cPanel.
2. Select your Database and export a full `.sql` backup.
3. Zip your current working website directory and download a copy. *If anything breaks, you can instantly restore it.*

### Step 2: Maintenance Mode (Optional but Recommended)
If you have SSH/Terminal access, put the site into maintenance mode so users don't interact with it while files are copying:
```bash
php artisan down --secret="update"
```
*(You can bypass the maintenance screen by visiting `yourdomain.com/update`)*

### Step 3: The Safe Upload (File Replacement)
To apply the new update, you must replace the old core files with the new ones, **while protecting your configuration**.

1. Download the latest version of the platform `.zip`.
2. Extract the new `.zip` package onto your computer or into a temporary folder on your server.
3. **Delete** the following from the *newly extracted update folder* before moving them to your live server:
   - `storage/` *(Never overwrite this, it holds your live app data and school files)*
   - `.env` *(Never replace this, it holds your database keys)*
4. Now, copy all remaining files and folders from the newly extracted folder and paste them into your live server directory, **overwriting the old files**.

### Step 4: Run Database Migrations
New features usually require columns to be added to your database. You **must** run migrations so the software structure updates.
1. Open your Server **Terminal** (aaPanel or cPanel).
2. Navigate to your website deployment folder (e.g., `cd /www/wwwroot/yourdomain.com` or `cd public_html`).
3. Run the migration command:
   ```bash
   php artisan migrate --force
   ```
*(Note: Do NOT add `--seed` during an update, or it will inject dummy data! The `--force` flag just skips the production warning).*

### Step 5: Flush Server Caches
Since the code has changed, Laravel's cache memory needs to be purged.
**Option A (Terminal):**
```bash
php artisan optimize:clear
```
**Option B (Visual Dashboard):**
1. Log into the system as SuperAdmin.
2. Go to **Platform Server Status**.
3. Under the **Quick Maintenance** card, click **View Cache** and **Config Cache**.

### Step 6: Go Live
If you put your site in maintenance mode during Step 2, bring it back online:
```bash
php artisan up
```

---

## ✅ Post-Update Verification

1. Navigate to your ERP Dashboard and perform a hard refresh (`Ctrl + F5` or `Cmd + Shift + R`) to force your browser to load any new CSS/Javascript styles.
2. Visit the **Platform Server Status** page.
3. Check the **MySQL Health & Footprint** card to ensure it's reading your data.
4. Click the **Run System Diagnostics** button to confirm the environment configurations successfully survived the update!
