# ShopDB Documentation

**Last Updated:** 2025-11-25
**Current Status:** Phase 2 Complete, Phase 3 Planned

---

## Project Status Overview

### Migration Progress

| Phase | Status | Description | Completed |
|-------|--------|-------------|-----------|
| **Phase 1** | COMPLETE | Schema changes - new tables, columns, indexes | Nov 6, 2025 |
| **Phase 2** | COMPLETE | PC migration to unified machines table | Nov 10, 2025 |
| **Phase 3** | PLANNED | Network devices migration (servers, switches, cameras) | TBD |

### Current Architecture

```
machines table (unified)
  ├── Equipment (machinetypeid 1-24, pctypeid IS NULL)
  └── PCs (machinetypeid 25-29, pctypeid IS NOT NULL)

printers table (separate - by design)

Network devices (Phase 3 will migrate):
  - servers, switches, cameras, accesspoints, idfs
  - Will become machinetypeid 30-36 in machines table
```

### Key Accomplishments (Oct-Nov 2025)

- Consolidated PCs into unified `machines` table (277 PCs migrated)
- Created `communications` table for all network interfaces (705+ records)
- Created `machinerelationships` table for PC/equipment relationships
- Modernized all PC pages (displaypcs, displaypc, editpc)
- Fixed 36+ API bugs for PowerShell data collection
- Added compliance and warranty tracking infrastructure
- Implemented network map for all device types

---

## Documentation Overview

### For New Team Members

**Start here in this order:**

1. **[QUICK_REFERENCE.md](QUICK_REFERENCE.md)** - Quick facts, common tasks, cheat sheets (15 min)

2. **[ASP_DEVELOPMENT_GUIDE.md](ASP_DEVELOPMENT_GUIDE.md)** - Dev environment setup, VBScript patterns (30 min)

3. **[STANDARDS.md](STANDARDS.md)** - Coding standards, security requirements (45 min)

4. **[DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md)** - Complete database/architecture docs (reference)

5. **[NESTED_ENTITY_CREATION.md](NESTED_ENTITY_CREATION.md)** - Complex forms, inline entity creation (20 min)

---

## Migration Documentation

### Phase 1 & 2 (Complete)

| Document | Description |
|----------|-------------|
| [DATABASE_MIGRATION_FINAL_DESIGN.md](DATABASE_MIGRATION_FINAL_DESIGN.md) | Complete Phase 1 specification |
| [MIGRATION_QUICK_REFERENCE.md](MIGRATION_QUICK_REFERENCE.md) | Quick lookup for migration |
| [PC_MACHINES_CONSOLIDATION_PLAN.md](PC_MACHINES_CONSOLIDATION_PLAN.md) | Phase 2 PC migration plan |
| [MACHINE_RELATIONSHIPS_EXAMPLES.md](MACHINE_RELATIONSHIPS_EXAMPLES.md) | Relationship query patterns |

### Phase 3 (Planned)

| Document | Description |
|----------|-------------|
| [PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md](PHASE3_NETWORK_DEVICES_MIGRATION_PLAN.md) | Network devices migration plan |

---

## Core Documentation

### Standards & Development

| Document | Purpose | Status |
|----------|---------|--------|
| [STANDARDS.md](STANDARDS.md) | Coding standards, security | Current |
| [ASP_DEVELOPMENT_GUIDE.md](ASP_DEVELOPMENT_GUIDE.md) | Dev setup, patterns | Current |
| [QUICK_REFERENCE.md](QUICK_REFERENCE.md) | Cheat sheets | Current |
| [NESTED_ENTITY_CREATION.md](NESTED_ENTITY_CREATION.md) | Complex forms | Current |

### Architecture & Design

| Document | Purpose | Status |
|----------|---------|--------|
| [DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md) | Complete system documentation | Current |
| [INFRASTRUCTURE_FINAL_ARCHITECTURE.md](INFRASTRUCTURE_FINAL_ARCHITECTURE.md) | Infrastructure design | Current |
| [NETWORK_DEVICES_UNIFIED_DESIGN.md](NETWORK_DEVICES_UNIFIED_DESIGN.md) | Network unification design | Current |

---

## SQL Migration Scripts

All migration scripts are in `/sql/migration_phase*/` folders:

```
sql/
├── migration_phase1/     # Schema changes (8 scripts + rollbacks)
├── migration_phase2/     # PC data migration (8 scripts)
├── migration_phase3/     # Network devices (planned)
└── *.sql                 # Utility scripts
```

---

## Quick Start

### Dev Environment

```bash
# Start dev environment
~/start-dev-env.sh

# Check status
~/status-dev-env.sh

# Access application
http://192.168.122.151:8080
```

### Git (Gitea)

```bash
# Gitea web UI
http://localhost:3000

# Clone repo
git clone ssh://git@localhost:2222/cproudlock/shopdb.git
```

### Database

```bash
# Connect to MySQL
docker exec -it dev-mysql mysql -u root -prootpassword shopdb

# Quick queries
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL;  -- PCs
SELECT COUNT(*) FROM machines WHERE pctypeid IS NULL;      -- Equipment
SELECT COUNT(*) FROM printers WHERE isactive = 1;          -- Printers
```

---

## Key Database Tables

### Core Tables (Phase 2 Schema)

| Table | Purpose | Records |
|-------|---------|---------|
| `machines` | All equipment + PCs | 500+ |
| `communications` | Network interfaces | 700+ |
| `machinerelationships` | PC/equipment links | 50+ |
| `printers` | Printers (separate) | 200+ |
| `warranties` | Warranty tracking | var |
| `compliance` | Compliance data | var |

### Key Views

| View | Purpose |
|------|---------|
| `vw_network_devices` | All network devices unified |
| `vw_active_pcs` | Active PCs with details |
| `vw_machine_relationships` | Relationship summary |

---

## Recent Session Summaries

Located in project root:

| File | Date | Focus |
|------|------|-------|
| SESSION_SUMMARY_2025-11-13.md | Nov 13 | Phase 2 testing, network_map fixes |
| SESSION_SUMMARY_2025-11-10.md | Nov 10 | Relationship fixes, Phase 3 planning |

---

## Getting Help

1. Check [QUICK_REFERENCE.md](QUICK_REFERENCE.md) first
2. Search [DEEP_DIVE_REPORT.md](DEEP_DIVE_REPORT.md)
3. Review [STANDARDS.md](STANDARDS.md) for coding questions
4. Check session summaries for recent changes

---

## Version History

| Version | Date | Changes |
|---------|------|---------|
| v2.0 | 2025-11-25 | Updated for Phase 2 completion, cleanup |
| v1.3 | 2025-10-20 | Added Git workflow documentation |
| v1.2 | 2025-10-20 | Added DEEP_DIVE_REPORT, QUICK_REFERENCE |
| v1.1 | 2025-10-10 | Added STANDARDS, NESTED_ENTITY_CREATION |
| v1.0 | 2025-10-09 | Initial ASP_DEVELOPMENT_GUIDE |

---

**Maintained By:** Development Team
**Last Updated:** 2025-11-25
