# SQM_Update_101.ps1 - Quick Reference

**Version:** 1.0.1-alpha  
**Update Type:** Feature + Patch  
**Files Changed:** 3

---

## Pre-Update Checklist

- [ ] Dev changes are in `C:\___Work\SqliteMojo\Web\`
- [ ] Production is in `C:\___Fire\SqliteMojo\Web\`
- [ ] Backup path exists: `C:\___Fire\SqliteMojo\Backups\`
- [ ] IIS app pool is stopped or user has file lock permissions
- [ ] Notify team of maintenance window

---

## Quick Commands

### Test Run (Safe - No Changes)

```powershell
cd C:\___Fire\SqliteMojo\
.\Updates\SQM_Update_101.ps1 -DryRun
```

**Output:** Shows what WOULD be deployed without making changes

---

### Live Deployment

```powershell
cd C:\___Fire\SqliteMojo\
.\Updates\SQM_Update_101.ps1
```

**Process:**
1. Validates prerequisites (2-3 sec)
2. Creates backup (10-20 sec)
3. Deploys files (5-10 sec)
4. Creates ordinations (2-5 sec)
5. Verifies hashes (5-10 sec)
6. Updates version files (1-2 sec)

**Total time:** ~30-60 seconds

---

### With Custom Paths

```powershell
.\Updates\SQM_Update_101.ps1 `
  -PreProdPath "C:\___Work\SqliteMojo\Web" `
  -ProdPath "C:\___Fire\SqliteMojo\Web" `
  -BackupPath "C:\___Fire\SqliteMojo\Backups"
```

---

## What Gets Updated

| File | Current | After | Notes |
|------|---------|-------|-------|
| `Admin\MigrationExecutor.aspx` | v1.0.0 | v1.0.1 | Multi-app UI redesign |
| `Admin\MigrationAnalyzer.ashx` | v1.0.0 | v1.0.1 | Multi-app support |
| `App_MasterPages\layout.Master` | v1.0.0 | v1.0.1 | SSI fix |

---

## Ordinations Created

After successful deployment, these files exist in `C:\___Fire\SqliteMojo\Web\Updates\Ordinations\`:

```
MigrationExecutor.aspx.101  ← Audit copy of v1.0.1
MigrationAnalyzer.ashx.101  ← Audit copy of v1.0.1
layout.Master.101           ← Audit copy of v1.0.1
```

Each file's `LastWriteTime` is the exact deployment timestamp.

---

## Backup Location

```
C:\___Fire\SqliteMojo\Backups\SQM_Update_101_20250115_143045\
├─ Admin\MigrationExecutor.aspx  [pre-update copy]
├─ Admin\MigrationAnalyzer.ashx  [pre-update copy]
└─ App_MasterPages\layout.Master [pre-update copy]
```

**Used for:** Quick rollback if needed

---

## Output Example

```
================================================================================
  SQM_Update_101 - Multi-App Siphon Enhancement
================================================================================
→ [14:30:45] Pre-Production: C:\___Work\SqliteMojo\Web
→ [14:30:45] Production:     C:\___Fire\SqliteMojo\Web
→ [14:30:45] Backup Path:    C:\___Fire\SqliteMojo\Backups\SQM_Update_101_20250115_143045
→ [14:30:45] Update Mode:    LIVE

================================================================================
  Phase 1: Validating Prerequisites
================================================================================
✓ [14:30:45] Pre-production root validated: C:\___Work\SqliteMojo\Web
✓ [14:30:45] Production root validated: C:\___Fire\SqliteMojo\Web
✓ [14:30:45] Pre-prod file: Admin\MigrationExecutor.aspx
✓ [14:30:45] Pre-prod file: Admin\MigrationAnalyzer.ashx
✓ [14:30:45] Pre-prod file: App_MasterPages\layout.Master
✓ [14:30:45] All prerequisites validated

================================================================================
  Phase 2: Creating Backup
================================================================================
✓ [14:30:46] Backed up: Admin\MigrationExecutor.aspx
✓ [14:30:46] Backed up: Admin\MigrationAnalyzer.ashx
✓ [14:30:46] Backed up: App_MasterPages\layout.Master
✓ [14:30:46] Backup complete: C:\___Fire\SqliteMojo\Backups\SQM_Update_101_20250115_143045

================================================================================
  Phase 3: Deploying Files and Creating Ordination
================================================================================
✓ [14:30:47] Deployed: Admin\MigrationExecutor.aspx
✓ [14:30:47] Ordinated: MigrationExecutor.aspx.101 (v101)
✓ [14:30:47] Deployed: Admin\MigrationAnalyzer.ashx
✓ [14:30:47] Ordinated: MigrationAnalyzer.ashx.101 (v101)
✓ [14:30:48] Deployed: App_MasterPages\layout.Master
✓ [14:30:48] Ordinated: layout.Master.101 (v101)
→ [14:30:48] Deployment: 3/3 files deployed

================================================================================
  Phase 4: Verifying Deployments
================================================================================
✓ [14:30:49] Verified: Admin\MigrationExecutor.aspx (hashes match)
✓ [14:30:49] Verified: Admin\MigrationAnalyzer.ashx (hashes match)
✓ [14:30:49] Verified: App_MasterPages\layout.Master (hashes match)
✓ [14:30:49] All files verified successfully

================================================================================
  Phase 5: Updating Version Tracking
================================================================================
✓ [14:30:50] Updated VERSION.md
✓ [14:30:50] Updated VERSION_HISTORY.md

================================================================================
  Update Summary
================================================================================

Update Statistics:
  Total Files:       3
  Deployed:          3
  Failed:            0
  Update Version:    101 (1.0.1)
  Backup Location:   C:\___Fire\SqliteMojo\Backups\SQM_Update_101_20250115_143045
  Ordination Folder: C:\___Fire\SqliteMojo\Web\Updates\Ordinations
  Log File:          C:\___Fire\SqliteMojo\Web\Updates\SQM_Update_101_Log.txt

✓ [14:30:50] Update SQM_Update_101 COMPLETED SUCCESSFULLY
✓ [14:30:50] Production is now at version 1.0.1-alpha
→ [14:30:50] Detailed log saved to: C:\___Fire\SqliteMojo\Web\Updates\SQM_Update_101_Log.txt
```

---

## Rollback (If Needed)

### Quick Rollback

```powershell
# Use the automatic backup from this update
Copy-Item -Path "C:\___Fire\SqliteMojo\Backups\SQM_Update_101_*\*" `
          -Destination "C:\___Fire\SqliteMojo\Web" -Recurse -Force
```

### Selective Rollback (One File)

```powershell
# Roll back just layout.Master to pre-101
$backup = Get-ChildItem "C:\___Fire\SqliteMojo\Backups\SQM_Update_101_*" | 
          Sort-Object Name -Descending | Select-Object -First 1

Copy-Item -Path "$($backup.FullName)\App_MasterPages\layout.Master" `
          -Destination "C:\___Fire\SqliteMojo\Web\App_MasterPages\layout.Master" -Force
```

### Restore from Ordination (v1.0.0)

```powershell
# If you kept 100 ordinations, restore them
$ordinations = Get-ChildItem "C:\___Fire\SqliteMojo\Web\Updates\Ordinations\*.100"
Copy-Item -Path $ordinations -Destination "C:\___Fire\SqliteMojo\Web" -Force
```

---

## Troubleshooting

### Script Won't Run

```powershell
# Check execution policy
Get-ExecutionPolicy

# If restricted, allow script:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

### "Path not found" Error

```powershell
# Verify paths exist
Test-Path "C:\___Work\SqliteMojo\Web"
Test-Path "C:\___Fire\SqliteMojo\Web"
Test-Path "C:\___Fire\SqliteMojo\Backups"
```

### File Lock Issues

```powershell
# IIS may be holding file locks
# Option 1: Stop app pool
iisreset /STOP

# Do update

# Option 2: Restart after update
iisreset /START
```

### Verification Failed

- Check log: `C:\___Fire\SqliteMojo\Web\Updates\SQM_Update_101_Log.txt`
- Verify backup is intact
- Check file permissions
- Consider rollback

---

## Post-Update Verification

### Check Version

```powershell
# Should show 1.0.1-alpha
Get-Content "C:\___Fire\SqliteMojo\Web\VERSION.md" | Select-Object -First 5
```

### Verify Files

```powershell
# Check that files exist and have correct timestamp
Get-Item "C:\___Fire\SqliteMojo\Web\Admin\MigrationExecutor.aspx" | 
  Select-Object Name, LastWriteTime, Length
```

### Test Portal

```powershell
# Access the portal UI
Start-Process "https://phosend.com/Portal/Admin/Pages/Default.aspx"

# Click DevAdmin → Siphon (Migration) to verify UI loaded
```

---

## Get Help

**View update log:**
```powershell
Get-Content "C:\___Fire\SqliteMojo\Web\Updates\SQM_Update_101_Log.txt"
```

**Check version history:**
```powershell
Get-Content "C:\___Fire\SqliteMojo\Web\Updates\VERSION_HISTORY.md" | tail -50
```

**List all ordinations:**
```powershell
Get-ChildItem "C:\___Fire\SqliteMojo\Web\Updates\Ordinations\" | 
  Select-Object Name, LastWriteTime | Sort-Object Name -Descending
```

---

**Questions? Review ORDINATION_VERSIONING_GUIDE.md for detailed info.** 🎯
