# IKEv2 Master Consistency Runbook

## Goal
- Treat shop DB as master and verify/repair drift against:
  - paid profile source table: vpnid_list
  - per-server provisioning queue status

## 1) Dry-run consistency check
```bash
php __CRON/cron_ikev2_consistency_check_cli.php --limit=100
```

Expected:
- inconsistent_items = 0

## 2) Focus one order
```bash
php __CRON/cron_ikev2_consistency_check_cli.php --od_id=YOUR_OD_ID --limit=20
```

## 3) Auto-fix inconsistencies
```bash
php __CRON/cron_ikev2_consistency_check_cli.php --apply-fix --limit=100
```

What fix does:
- Re-sync vpnid_list from order/cart/item master data.
- Requeue provisioning push to IKEv2 servers.

## 4) Retry failed vpnid sync jobs
```bash
php __CRON/cron_ikev2_vpnid_sync_retry_cli.php --limit=50
```

## 5) SQL dashboard snippets
```sql
-- A. vpnid sync queue status
SELECT sync_id, od_id, it_id, trigger_source, final_status, fail_count, next_retry_at, updated_at
FROM app_ikev2_vpnid_sync_queue
ORDER BY sync_id DESC
LIMIT 100;
```

```sql
-- B. provisioning queue status
SELECT queue_id, od_id, it_id, server_ip, vpn_user_id, final_status, fail_count, next_retry_at, updated_at
FROM app_ikev2_provision_queue
ORDER BY queue_id DESC
LIMIT 200;
```

```sql
-- C. paid profile source rows
SELECT no, member_id, server_name, member_id_expire, enable, od_id,
       COALESCE(update_datetime, datetime) AS touched_at
FROM vpnid_list
ORDER BY no DESC
LIMIT 200;
```

## 6) VS Code tasks
- IKEv2 VPNID Sync: Retry Queue (CLI)
- IKEv2 VPNID Sync: Retry Queue (Web 3000)

## Release check
- recent paid orders show final_status=success in both queues
- vpnid_list row exists per member_id + server_name target
- no stale retry backlog (next_retry_at overdue rows close to 0)

## Interpretation Guide
- inconsistent_items decreases after apply-fix: expected behavior.
- remaining provision_not_success means remote server push is still retrying/failed; run retry jobs and inspect app_ikev2_provision_queue last_error.
- remaining expire_mismatch/password_mismatch can occur while multiple records for same member/server are being converged; rerun consistency check after retry cycle.
