# EMA SalesDock (North East): test it on live data today, switch over tomorrow

**The idea**
- **Today:** the new SalesDock runs at **ne.salesdock.name.ng**, with its **own folder** and its **own database**. That database is a copy of the live one, refreshed whenever you press a button.
  - The old app at **ema.azar.com.ng** keeps running exactly as it is.
  - Its folder and its database are **never changed**. The new site reads the old database through a user that is only allowed to read.
- **Tomorrow:**
  1. Point ema.azar.com.ng to the new site.
  2. Take one last copy.
  3. Switch off "test mode".
  4. The new database becomes the real one. The old database stays untouched as a backup.

```
TODAY     ema.azar.com.ng  ── old app ──► wposqayq_ema_sales_db  (live, unchanged)
                                                   │ read only (copy button)
                                                   ▼
          ne.salesdock.name.ng ── new app ──► wposqayq_salesdock_ne  (test copy, upgraded)

TOMORROW  ema.azar.com.ng ──redirect──► ne.salesdock.name.ng ──► wposqayq_salesdock_ne (now the real one)
```

## Files in this package

| File | What it is |
|---|---|
| `salesdock-ne-app.zip` | The new SalesDock (Phases 1–5, plus the test-site tools). 165 files. No `.env`, `storage/` or `vendor/` |
| `htaccess-for-ema.azar.com.ng-TOMORROW.txt` | Tomorrow only: sends ema.azar.com.ng to the new site |
| `TESTING_PLAN_Phases_1-5.xlsx` | The 93-test checklist |
| `salesdock-home-page.zip` | Password page for salesdock.name.ng (optional) |
| `salesdock-full-source.zip` | Complete app, for your records. Do not upload |

You do **not** need any SQL file for this route. The copy button upgrades the copied database itself. That's the same upgrade that was tested against your live backup.

---

# PART 1: TODAY (about 45 minutes)

### 1. Two new MySQL users and one new database

Go to cPanel → **MySQL Databases**.

**a. New database:** name it `salesdock_ne`. cPanel makes it `wposqayq_salesdock_ne`.

**b. Test-site user**
1. Create user `sdne` with a strong password (it becomes `wposqayq_sdne`). Write the password down.
2. **Add User To Database:** `wposqayq_sdne` → `wposqayq_salesdock_ne` → tick **ALL PRIVILEGES**.

**c. Read-only user for the live database**
1. Create user `sdread` with a strong password (it becomes `wposqayq_sdread`). Write it down.
2. **Add User To Database:** `wposqayq_sdread` → `wposqayq_ema_sales_db` → tick **ONLY `SELECT`** (and `SHOW VIEW` if listed). Nothing else.

The new site checks this for itself. It refuses to copy if this user is allowed to change anything.

### 2. Copy the app folder (the old folder stays as it is)

1. File Manager → home folder → right-click **`ema.azar.com.ng`** → **Copy** → type `/salesdock-ne` → **Copy File(s)**. This makes `/home/wposqayq/salesdock-ne` with everything, including `vendor`. It takes a minute or two.
2. Open **`salesdock-ne`** (the NEW folder. Check the path at the top before going on):
   - Delete `fix.php` and `public/fix.php`.
   - **Upload** `salesdock-ne-app.zip` → **Extract** → **overwrite**. Then delete the zip.
3. ⚠️ **Never extract this zip into `ema.azar.com.ng`.** It would redirect the old site today.

### 3. Settings for the new site (before it goes online)

In **`salesdock-ne`**, edit **`.env`**:

1. Change these lines:
   ```
   APP_NAME="EMA SalesDock"
   APP_URL=https://ne.salesdock.name.ng
   APP_DEBUG=false
   LOG_LEVEL=error
   SESSION_SECURE_COOKIE=true

   DB_DATABASE=wposqayq_salesdock_ne
   DB_USERNAME=wposqayq_sdne
   DB_PASSWORD=the password from 1b
   ```
2. Add these lines at the end:
   ```
   SALESDOCK_REGION=NE
   SALESDOCK_REGION_LABEL="North East"

   # ---- TEST SITE (remove these tomorrow) ----
   SALESDOCK_STAGING=true
   SALESDOCK_STAGING_KEY=choose-a-secret-word-of-8-or-more-characters
   LIVE_DB_DATABASE=wposqayq_ema_sales_db
   LIVE_DB_USERNAME=wposqayq_sdread
   LIVE_DB_PASSWORD=the password from 1c
   ```
3. If there is a **`.env.production`** in `salesdock-ne`, make the same changes there.
4. Clear the copied cache:
   - delete the files (not the folders) in `storage/framework/views/` and `storage/framework/sessions/`
   - delete `bootstrap/cache/config.php` if it exists

Built-in safety: if `DB_DATABASE` is ever the live database, the test site refuses to open, with "TEST SITE MISCONFIGURED", and the copy refuses to run.

### 4. Point ne.salesdock.name.ng at the new folder

cPanel → **Domains**:

- **New domain:** Create A New Domain → `ne.salesdock.name.ng` → untick "Share document root" → document root **`salesdock-ne`** → Submit.
- **Domain already created** (pointing at `ema.azar.com.ng`): **Manage** → change the document root to **`salesdock-ne`** → Update.

Then go to **SSL/TLS Status** → `ne.salesdock.name.ng` → **Run AutoSSL**.

### 5. Fill the test database from live

1. Open **https://ne.salesdock.name.ng/staging-refresh**.
2. Type the secret word from step 3 → **Refresh test data from live**.
3. Wait. It reads about 100,000 rows. That took 9 seconds on my test machine; allow 1–3 minutes on the server. It ends with "Done in … seconds".
4. Every page now has a red strip: **"TEST SITE – a copy of live data (copied …)"**.
5. You can press the button again any time today to bring in the latest live entries.

If the page shows **"Cannot refresh yet"**, it says why. Most likely the read-only user (1c) or a password in `.env` is wrong.

### 6. Load your files on the test site (DA login)

Use DA → **Imports**, in this order:

1. KW mapping
2. SP customer mapping
3. Planning sheet (November, then December)
4. **Billing report** (.xlsx)
5. **SO-SI**

Then test the reports: **How Far**, **RSM View**, **Sales Plans**, **Region Reports** (all four Excel downloads, plus the monthly plan for December).

⚠️ A **refresh replaces everything on the test site**, including these imports. If you refresh again, upload them again. Tomorrow you'll do the imports once more, on the real system.

### 7. Testing

- Work through `TESTING_PLAN_Phases_1-5.xlsx`.
  - Tests about the **old address redirect** (L1-01) and **ema.azar.com.ng** are for tomorrow.
  - The automatic alert tests (9:00, before close, Wednesday) are for later in the week.
- You and a few volunteers can log in to the test site. Use the usual PINs. The first login asks for a new PIN, but only on the test copy.
- **Don't send the link to the whole team today.** Anything entered on the test site is wiped by the next refresh and never reaches the real system.
- **Alerts:** testers can tap 🔔 Alerts. Every test alert is marked **[TEST]**. The automatic alerts only run if you add the cron job:
  ```
  /usr/local/bin/php /home/wposqayq/salesdock-ne/artisan schedule:run >> /dev/null 2>&1
  ```
  - It's fine to add it today: it keeps working after tomorrow.
  - Only people who turned alerts on, on the test site, get anything.

**Tonight:** ask every SP to **Sync & submit** on the old app before they stop for the day. Entries still waiting on phones can't be moved across tomorrow.

---

# PART 2: TOMORROW, switch-over (about 30 minutes, before staff start)

1. **Back up the old database:** phpMyAdmin → `wposqayq_ema_sales_db` → Export → Go. This is a safety copy. The old database won't be changed anyway.
2. **Close the old address** (from here on, nobody can add to the old database):
   1. File Manager → `ema.azar.com.ng` → Settings → **Show Hidden Files**.
   2. Rename `.htaccess` to **`.htaccess-old-app`**.
   3. Upload `htaccess-for-ema.azar.com.ng-TOMORROW.txt` and rename it to **`.htaccess`**.
   4. Check: https://ema.azar.com.ng now goes to https://ne.salesdock.name.ng.
3. **Last copy:** https://ne.salesdock.name.ng/staging-refresh → secret word → **Refresh**. This brings everything, including yesterday's last entries, into the new database.
4. **Switch off test mode:** edit `salesdock-ne/.env` (and `.env.production` if present):
   - change `SALESDOCK_STAGING=true` to **`SALESDOCK_STAGING=false`**
   - **delete** the lines `SALESDOCK_STAGING_KEY`, `LIVE_DB_DATABASE`, `LIVE_DB_USERNAME` and `LIVE_DB_PASSWORD`
   - delete `bootstrap/cache/config.php` if it exists

   The red strip disappears, `/staging-refresh` stops working, and no copy can ever run again. **`wposqayq_salesdock_ne` is now the real SalesDock database.**
5. cPanel → MySQL Databases → **delete the user `wposqayq_sdread`**. It's no longer needed.
6. **Imports on the real system** (DA), in the same order as Part 1 step 6. Then do the **Priority 1** tests in the testing plan.
7. Send the WhatsApp message to the team (it's in the combined launch guide from Saturday). Optional: set up the salesdock.name.ng password page with `salesdock-home-page.zip`.

### Undo tomorrow (if something is badly wrong)

1. In `ema.azar.com.ng`, delete the new `.htaccess` and rename **`.htaccess-old-app`** back to `.htaccess`.
2. The old app works again straight away, with its database exactly as it was.

The only loss: anything entered on the new site after the switch, which you can re-enter.

---

### Checks done before packaging

- **Copy with a read-only user:** 40 tables and about 100,000 rows copied in 9 seconds, then upgraded. The live database was checked table by table afterwards: **unchanged**.
- **The safety refusals all work:**
  - not a test site
  - the test site pointing at the live database
  - a live-database user that can write
- **The upgraded copy** has exactly the same structure as the tested Phase 1–5 database. Login, DA pages, How Far, the RSM view, Region Reports and Alerts all work on the copy.
- **Secret word:** a wrong word is refused, and 5 wrong tries lock the page for 10 minutes.
- **On a normal (non-test) site,** `/staging-refresh` does not exist (404) and no banner shows.
- **All 260 automated tests still pass.**
- **The code zip:** copying today's live folder and extracting the zip gives exactly the new app, once the two `fix.php` files are deleted.
