# Setup Automatic CNPERP Updates (Windows)

## One-Minute Setup ⚡

**Option 1: Double-Click (Easiest)**
1. Right-click: `C:\dev\cnperp-dimensions\deploy\setup_auto_update.bat`
2. Select "Run as Administrator"
3. Done! Updates will run nightly at 2:00 AM

**Option 2: PowerShell (Advanced)**
See `SCHEDULED_TASK_SETUP.md` for detailed instructions

---

## What Gets Automated

Every night at **2:00 AM**:
- ✅ Database backup (pre-update)
- ✅ Git pull (latest code)
- ✅ Pip upgrade (dependencies)
- ✅ Service restart (CNPERP)
- ✅ Logging (to `logs/auto_update.log`)

**Downtime**: ~30-60 seconds (users offline after hours)

---

## Verify It's Running

```powershell
# Check task status
Get-ScheduledTask -TaskName "CNPERP Auto-Update"

# View latest logs
Get-Content "C:\dev\cnperp-dimensions\logs\auto_update.log" -Tail 30

# Manually trigger a test run
Start-ScheduledTask -TaskName "CNPERP Auto-Update"
```

---

## Rollback (if needed)

Someone at the office can manually undo an update:
```powershell
cd C:\dev\cnperp-dimensions
git reset --hard HEAD@{1}
Restart-Service CNPERP
```

---

## Disable/Enable Updates

```powershell
# Pause updates
Disable-ScheduledTask -TaskName "CNPERP Auto-Update"

# Resume updates
Enable-ScheduledTask -TaskName "CNPERP Auto-Update"
```

---

## Files Involved

| File | Purpose |
|------|---------|
| `deploy/auto_update.ps1` | Main update script (runs automatically) |
| `deploy/setup_auto_update.bat` | One-click installer for scheduled task |
| `deploy/SCHEDULED_TASK_SETUP.md` | Detailed setup guide |
| `logs/auto_update.log` | Update history & logs |

---

## Next Steps

1. Run `setup_auto_update.bat` (right-click → Run as Administrator)
2. Check logs tomorrow morning: `logs/auto_update.log`
3. Done! Your app updates itself nightly.

Questions? Check the logs first—they explain what happened.
