directlx-claude-config/plans/composed-dreaming-sun.md

96 lines
4.3 KiB
Markdown

# Database Seed Script: 1000 ATMs with Realistic Test Data
## Goal
Create a comprehensive SQL seed script to populate the hiveops_incident database with ~1000 ATMs and proportional amounts of incidents, journal events, fleet tasks, and related data across all statuses.
## Output File
- `backend/src/main/resources/db/seed-data.sql` — single SQL script using PL/pgSQL DO blocks
## Approach
Use PostgreSQL PL/pgSQL procedural blocks with `generate_series` and `random()` for efficient bulk data generation. The script will:
1. Clear existing data (TRUNCATE CASCADE)
2. Insert all seed data in a single transaction
## Data Volumes
| Table | Count | Notes |
|-------|-------|-------|
| technicians | 30 | Various specializations, availability |
| atms | 1000 | Varied statuses, models, locations across 20 countries |
| atm_properties | 1000 | One per ATM, varied agent versions/platforms |
| incidents | ~4000 | ~35% OPEN, 20% ASSIGNED, 20% IN_PROGRESS, 15% RESOLVED, 10% CLOSED |
| incident_notes | ~4000 | 1-3 notes per non-OPEN incident |
| journal_events | ~50000 | All 23 event types, spread across last 30 days |
| fleet_artifacts | 12 | Mix of AGENT_JAR and MODULE_JAR |
| fleet_tasks | ~2000 | All 6 statuses (PENDING/QUEUED/RUNNING/COMPLETED/FAILED/CANCELLED) |
| atm_module_status | ~3000 | 2-4 modules per ATM (subset) |
| workflow_transitions | 8 | Standard transitions (same as existing) |
| settings | 1 | Default settings |
## Data Distribution Strategy
### ATMs (1000)
- **Statuses**: OPERATIONAL 70%, MAINTENANCE 15%, DOWN 10%, INACTIVE 5%
- **Models**: NCR SelfServ 84, NCR 6695, Hyosung MoniMax 8600, Hyosung MoniMax 8200, Diebold Nixdorf CS 5550, Diebold Opteva 750, Wincor ProCash 2250xe
- **Locations**: 20 countries (US, UK, DE, FR, NL, BE, AT, CH, ES, IT, PL, CZ, SE, NO, DK, FI, AU, CA, JP, KR) with realistic city/address per country
- **ATM IDs**: `{COUNTRY}-{CITY_CODE}-{SEQ}` pattern (e.g., `US-NYC-001`, `DE-BER-042`)
### Technicians (30)
- Specializations: Card Reader, Network Systems, Cash Handling, Hardware, Software, Security
- Availability: AVAILABLE 60%, BUSY 30%, OFFLINE 10%
- Varied ratings (3.5-5.0), resolution counts, locations
### Incidents (~4000)
- All 11 incident types with realistic weights (CASSETTE_LOW most common, PHYSICAL_DAMAGE least)
- All 4 severities: LOW 20%, MEDIUM 35%, HIGH 30%, CRITICAL 15%
- All 5 statuses with realistic distribution
- ASSIGNED/IN_PROGRESS/RESOLVED/CLOSED linked to technicians
- Timestamps spread across last 90 days
- RESOLVED/CLOSED have realistic resolution times
### Journal Events (~50000)
- All 23 event types with realistic frequency weights
- Event times spread across last 30 days (recent 7 days heavier)
- Event sources: API, REMOTE_MONITORING, MANUAL, SCHEDULED, HIVEOPS_AGENT
- Card reader events include slot/status fields
- Cassette events include type/fill/count/currency fields
### Fleet Tasks (~2000)
- Task kinds: UPDATE_CLIENT 50%, REBOOT 30%, RESTART_CLIENT 20%
- Statuses: PENDING 15%, QUEUED 10%, RUNNING 10%, COMPLETED 45%, FAILED 15%, CANCELLED 5%
- COMPLETED/FAILED have start/complete timestamps
- Some linked to fleet artifacts
### Fleet Artifacts (12)
- AGENT_JAR: hiveops-agent versions (1.0.0 through 1.5.2)
- MODULE_JAR: various modules (journal-parser, config-sync, health-monitor, etc.)
- Realistic file sizes and SHA256 hashes
## Script Structure
```sql
BEGIN;
-- 1. TRUNCATE all tables (CASCADE)
-- 2. Reset sequences
-- 3. INSERT technicians (30 rows, explicit)
-- 4. INSERT ATMs (1000 rows via generate_series DO block)
-- 5. INSERT atm_properties (1000 rows via DO block)
-- 6. INSERT fleet_artifacts (12 rows, explicit)
-- 7. INSERT incidents (~4000 via DO block with random distribution)
-- 8. INSERT incident_notes (via DO block for non-OPEN incidents)
-- 9. INSERT journal_events (~50000 via DO block)
-- 10. INSERT fleet_tasks (~2000 via DO block)
-- 11. INSERT atm_module_status (~3000 via DO block)
-- 12. INSERT workflow_transitions (8 rows, explicit)
-- 13. INSERT settings (1 row, explicit)
COMMIT;
```
## Verification
- Run: `psql -h <host> -U postgres -d hiveops_incident -f seed-data.sql`
- Verify counts: `SELECT 'atms', count(*) FROM atms UNION ALL SELECT 'incidents', count(*) FROM incidents ...`
- Start backend and check frontend pages: Dashboard, Incidents, Event Stats, Fleet Stats, Fleet Tasks