Consolidate documentation: archive 45+ historical docs
- Move completed migration docs to docs/archive/ - Move session summaries to docs/archive/sessions/ - Rename API_ASP_DOCUMENTATION.md to docs/API.md - Archive redundant Claude reference files - Update docs/README.md as simplified index - Reduce active docs from 45+ files to 8 essential files Remaining docs: - CLAUDE.md (AI context) - TODO.md (task tracking) - docs/README.md, API.md, QUICK_REFERENCE.md - docs/ASP_DEVELOPMENT_GUIDE.md, STANDARDS.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
721
docs/archive/PHASE2_DEV_MIGRATION_NOTES.md
Normal file
721
docs/archive/PHASE2_DEV_MIGRATION_NOTES.md
Normal file
@@ -0,0 +1,721 @@
|
||||
# Phase 2 PC Migration - DEV Server Actual Execution Notes
|
||||
|
||||
**Environment:** Development Server (IIS Express on Windows 11 VM + MySQL 5.6 in Docker)
|
||||
**Date Executed:** November 13, 2025
|
||||
**Status:** COMPLETE
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
Phase 2 PC Migration was successfully completed on the DEV server. This document records the **actual steps taken**, including manual interventions required beyond the original migration scripts.
|
||||
|
||||
**Key Results:**
|
||||
- 224 PCs migrated from `pc` table → `machines` table
|
||||
- 705 network interfaces migrated to `communications` table
|
||||
- 221 PC-to-machine ID mappings created
|
||||
- 11 ASP page files updated to use Phase 2 schema
|
||||
- All PC functionality verified working
|
||||
|
||||
---
|
||||
|
||||
## Pre-Migration State
|
||||
|
||||
### Database Schema Issues Found
|
||||
|
||||
The dev database was in an incomplete state:
|
||||
- `communications` table existed but was **EMPTY** (0 records)
|
||||
- `machines` table **MISSING** critical PC-related columns:
|
||||
- `pctypeid` column did not exist
|
||||
- `loggedinuser` column did not exist
|
||||
- `machinestatusid` column did not exist
|
||||
- `lastupdated` column did not exist
|
||||
- 276 PCs still in old `pc` table
|
||||
- Phase 1 scripts had been partially run but not completed
|
||||
|
||||
### ASP Page Status
|
||||
|
||||
Many PC pages had already been updated to expect Phase 2 schema:
|
||||
- `displaypcs.asp` - Already querying `machines WHERE pctypeid IS NOT NULL`
|
||||
- `displaypc.asp` - Already using Phase 2 schema
|
||||
- `editpc.asp` - Already using Phase 2 schema
|
||||
- But database didn't match the code expectations!
|
||||
|
||||
---
|
||||
|
||||
## Migration Steps Actually Performed
|
||||
|
||||
### Step 1: Add Missing Columns to machines Table
|
||||
|
||||
**Issue:** Phase 2 migration script expected these columns to exist, but they didn't.
|
||||
|
||||
**Manual SQL executed:**
|
||||
|
||||
```sql
|
||||
-- Add pctypeid column (critical for identifying PCs vs equipment)
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN pctypeid INT(11) AFTER machinetypeid;
|
||||
|
||||
-- Add loggedinuser column
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN loggedinuser VARCHAR(100) AFTER hostname;
|
||||
|
||||
-- Add machinestatusid column
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN machinestatusid INT(11) AFTER osid;
|
||||
|
||||
-- Add lastupdated column (replaces dateadded)
|
||||
ALTER TABLE machines
|
||||
ADD COLUMN lastupdated DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
|
||||
```
|
||||
|
||||
**Note:** User explicitly requested NOT to add `dateadded` column, only `lastupdated`.
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
DESCRIBE machines;
|
||||
-- Confirmed all 4 columns added successfully
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 2: Run Phase 1 Infrastructure Scripts
|
||||
|
||||
Since Phase 1 was incomplete, ran these scripts:
|
||||
|
||||
```bash
|
||||
cd /home/camp/projects/windows/shopdb/sql/migration_phase1/
|
||||
|
||||
# Create communications infrastructure
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 01_create_communications_infrastructure.sql
|
||||
|
||||
# Create PC machine types (28-32)
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 03_create_pc_machine_types.sql
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- `comstypes` table: 8 communication types created
|
||||
- `communications` table: Structure created (still empty)
|
||||
- PC machine types 28-32 created in `machinetypes` table
|
||||
|
||||
---
|
||||
|
||||
### Step 3: Run Phase 2 PC Migration Script
|
||||
|
||||
```bash
|
||||
cd /home/camp/projects/windows/shopdb/sql/migration_phase2/
|
||||
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 01_migrate_pcs_to_machines.sql
|
||||
```
|
||||
|
||||
**Error Encountered:**
|
||||
```
|
||||
Unknown column 'pctypeid' in 'where clause'
|
||||
Unknown column 'lastupdated' in 'field list'
|
||||
```
|
||||
|
||||
**Resolution:** Already fixed in Step 1 (added missing columns). Re-ran script successfully.
|
||||
|
||||
**Results:**
|
||||
- 224 PCs migrated from `pc` → `machines`
|
||||
- All PCs now have `pctypeid IS NOT NULL`
|
||||
- `pc_to_machine_id_mapping` table created (but was EMPTY!)
|
||||
|
||||
---
|
||||
|
||||
### Step 4: Fix Empty Mapping Table
|
||||
|
||||
**Issue:** Script created `pc_to_machine_id_mapping` table but it had 0 records!
|
||||
|
||||
**Root Cause:** Migration script Step 7 tried to insert mappings but failed silently due to duplicate hostnames.
|
||||
|
||||
**Manual Fix:**
|
||||
|
||||
```sql
|
||||
-- Populate mapping table (handles duplicates with MIN)
|
||||
INSERT INTO pc_to_machine_id_mapping (pcid, old_hostname, new_machineid, new_machinenumber)
|
||||
SELECT p.pcid,
|
||||
p.hostname,
|
||||
MIN(m.machineid) AS new_machineid,
|
||||
MIN(m.machinenumber) AS new_machinenumber
|
||||
FROM pc p
|
||||
JOIN machines m ON m.hostname = p.hostname
|
||||
WHERE p.isactive = 1 AND m.pctypeid IS NOT NULL
|
||||
GROUP BY p.pcid, p.hostname;
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 221 mappings created (out of 224 PCs)
|
||||
- 3 PCs couldn't be mapped (duplicate hostname issue: pcid 59 & 164 both had "G5G9S624ESF")
|
||||
- Used `MIN(machineid)` to select first match for duplicates
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM pc_to_machine_id_mapping;
|
||||
-- Result: 221 rows
|
||||
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL;
|
||||
-- Result: 224 rows
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5: Migrate Network Interfaces
|
||||
|
||||
```bash
|
||||
mysql -h 192.168.122.1 -u root -p shopdb < 02_migrate_network_interfaces_to_communications.sql
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 705 network interfaces migrated to `communications` table
|
||||
- Used `pc_to_machine_id_mapping` to link old pcid to new machineid
|
||||
- `comstypeid` set to 1 (Network_Interface type)
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM communications WHERE comstypeid = 1;
|
||||
-- Result: 705 rows
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5.5: Migrate PC-to-Machine Relationships
|
||||
|
||||
**Issue:** The `machinerelationships` table was empty. Phase 2 script 05 (dualpath) wasn't sufficient.
|
||||
|
||||
**Discovery:** The old `pc` table has a `machinenumber` column that stores which equipment each PC controls!
|
||||
|
||||
**Manual SQL executed:**
|
||||
|
||||
```sql
|
||||
-- Create Controls relationships from old pc.machinenumber
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT DISTINCT
|
||||
equipment.machineid AS equipment_machineid,
|
||||
pc_migrated.machineid AS pc_machineid,
|
||||
3 AS relationshiptypeid, -- 'Controls' relationship
|
||||
1 AS isactive
|
||||
FROM pc old_pc
|
||||
JOIN machines equipment ON equipment.machinenumber = old_pc.machinenumber
|
||||
JOIN machines pc_migrated ON pc_migrated.hostname = old_pc.hostname
|
||||
WHERE old_pc.isactive = 1
|
||||
AND old_pc.machinenumber IS NOT NULL
|
||||
AND old_pc.machinenumber != ''
|
||||
AND equipment.pctypeid IS NULL -- Equipment only
|
||||
AND pc_migrated.pctypeid IS NOT NULL -- PCs only
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships mr
|
||||
WHERE mr.machineid = equipment.machineid
|
||||
AND mr.related_machineid = pc_migrated.machineid
|
||||
AND mr.relationshiptypeid = 3
|
||||
);
|
||||
```
|
||||
|
||||
**Results:**
|
||||
- 142 PC-to-equipment "Controls" relationships created
|
||||
- Plus 6 from hostname matching = **148 total relationships**
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM machinerelationships;
|
||||
-- Result: 148 rows
|
||||
|
||||
-- Example: Machine 130 controlled by PC 390
|
||||
SELECT
|
||||
equipment.machinenumber AS equipment,
|
||||
pc.hostname AS controlling_pc
|
||||
FROM machinerelationships mr
|
||||
JOIN machines equipment ON mr.machineid = equipment.machineid
|
||||
JOIN machines pc ON mr.related_machineid = pc.machineid
|
||||
WHERE equipment.machineid = 130;
|
||||
-- Result: 2001 | GB07T5X3ESF
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Step 5.6: Migrate Dualpath Relationships
|
||||
|
||||
**Date:** November 13, 2025
|
||||
|
||||
**Issue:** The `machinerelationships` table had 0 dualpath relationships, but `pc_dualpath_assignments` table contained 33 dualpath assignments.
|
||||
|
||||
**Script Used:**
|
||||
```bash
|
||||
mysql -u570005354 -p shopdb < sql/migration_phase2/05_migrate_dualpath_assignments.sql
|
||||
```
|
||||
|
||||
**What the script does:**
|
||||
- Reads `pc_dualpath_assignments` table (33 dualpath pairs)
|
||||
- Creates bidirectional relationships in `machinerelationships`:
|
||||
- primary_machine → secondary_machine (relationshiptypeid = 1)
|
||||
- secondary_machine → primary_machine (relationshiptypeid = 1)
|
||||
- Uses `pc_to_machine_id_mapping` to link old pcid to new machineid
|
||||
|
||||
**Results:**
|
||||
- 31 dualpath relationships created (direction 1)
|
||||
- 31 dualpath relationships created (direction 2)
|
||||
- **Total: 62 dualpath relationships** (31 pairs)
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
SELECT rt.relationshiptype, COUNT(*) as count
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE mr.isactive = 1
|
||||
GROUP BY rt.relationshiptype;
|
||||
-- Result: Controls: 148, Dualpath: 62
|
||||
|
||||
-- Example dualpath pair: Machines 2003 and 2004
|
||||
SELECT m1.machinenumber, m2.machinenumber, rt.relationshiptype
|
||||
FROM machinerelationships mr
|
||||
JOIN machines m1 ON mr.machineid = m1.machineid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE m1.machinenumber IN ('2003', '2004') AND rt.relationshiptype = 'Dualpath';
|
||||
-- Result shows bidirectional: 2003→2004 and 2004→2003
|
||||
```
|
||||
|
||||
**Note:** Backup created in `pc_dualpath_assignments_backup_phase2` table.
|
||||
|
||||
---
|
||||
|
||||
### Step 6: Update ASP Pages
|
||||
|
||||
**Files Still Using Old `pc` Table:**
|
||||
|
||||
Found 7 files that still referenced the old `pc` table and needed updating:
|
||||
|
||||
#### 6.1 Warranty Checking Files (3 files)
|
||||
|
||||
**Files Updated:**
|
||||
- `check_all_warranties.asp`
|
||||
- `check_all_warranties_clean.asp`
|
||||
- `check_warranties_v2.asp`
|
||||
|
||||
**Changes Made:**
|
||||
```asp
|
||||
' OLD: Query pc table
|
||||
SELECT pcid, hostname, serialnumber FROM pc WHERE isactive = 1
|
||||
|
||||
' NEW: Query machines table with pctypeid filter
|
||||
SELECT machineid, hostname, serialnumber FROM machines
|
||||
WHERE pctypeid IS NOT NULL AND isactive = 1
|
||||
|
||||
' OLD: Update warranty in pc table
|
||||
UPDATE pc SET warrantyenddate = ?, warrantyservicelevel = ? WHERE pcid = ?
|
||||
|
||||
' NEW: Insert into warranties table
|
||||
INSERT INTO warranties (machineid, enddate, servicelevel, lastcheckeddate)
|
||||
VALUES (?, ?, ?, NOW())
|
||||
ON DUPLICATE KEY UPDATE enddate = VALUES(enddate), servicelevel = VALUES(servicelevel)
|
||||
```
|
||||
|
||||
#### 6.2 Device Management Files (4 files)
|
||||
|
||||
**Files Updated:**
|
||||
- `editdevice.asp`
|
||||
- `savedevice.asp`
|
||||
- `savedevice_direct.asp`
|
||||
- `updatepc_direct.asp`
|
||||
|
||||
**Changes Made:**
|
||||
```asp
|
||||
' OLD: Check if device exists in pc table
|
||||
SELECT COUNT(*) FROM pc WHERE pcid = ?
|
||||
|
||||
' NEW: Check if device exists in machines table
|
||||
SELECT COUNT(*) FROM machines WHERE machineid = ? AND pctypeid IS NOT NULL
|
||||
|
||||
' OLD: Insert into pc table
|
||||
INSERT INTO pc (serialnumber, ...) VALUES (?, ...)
|
||||
|
||||
' NEW: Insert into machines table with pctypeid
|
||||
INSERT INTO machines (serialnumber, pctypeid, machinetypeid, ...)
|
||||
VALUES (?, 1, 28, ...)
|
||||
|
||||
' OLD: Update pc table
|
||||
UPDATE pc SET ... WHERE pcid = ?
|
||||
|
||||
' NEW: Update machines table
|
||||
UPDATE machines SET ... WHERE machineid = ? AND pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
**Key Pattern:** All queries now filter with `pctypeid IS NOT NULL` to distinguish PCs from equipment.
|
||||
|
||||
---
|
||||
|
||||
### Step 7: Fix Additional Pages
|
||||
|
||||
**Files with Other Issues Found:**
|
||||
|
||||
#### 7.1 displaypcs.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Changed to `lastupdated`
|
||||
```asp
|
||||
' OLD: SELECT machines.dateadded
|
||||
' NEW: SELECT machines.lastupdated
|
||||
```
|
||||
|
||||
#### 7.2 displaypc.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Removed from SELECT query entirely (not displayed)
|
||||
|
||||
#### 7.3 displaymachine.asp
|
||||
**Issue:** Referenced non-existent `dateadded` column
|
||||
**Fix:** Removed from SELECT query
|
||||
```asp
|
||||
' OLD: "machines.lastupdated, machines.dateadded, " & _
|
||||
' NEW: "machines.lastupdated, " & _
|
||||
```
|
||||
|
||||
#### 7.4 displaysubnet.asp
|
||||
**Issue:** Queried old `pc_network_interfaces` table
|
||||
**Fix:** Changed to query `communications` table
|
||||
```asp
|
||||
' OLD: SELECT pcid FROM pc_network_interfaces WHERE ipaddress = ?
|
||||
' NEW: SELECT c.machineid FROM communications c
|
||||
' JOIN machines m ON c.machineid = m.machineid
|
||||
' WHERE c.address = ? AND m.pctypeid IS NOT NULL
|
||||
```
|
||||
|
||||
#### 7.5 network_map.asp
|
||||
**Issue:** Expected Phase 3 network devices (not yet migrated)
|
||||
**Fix:** Removed broken UNION query for network devices, kept only printers
|
||||
```asp
|
||||
' Removed: UNION query for network devices from machines table
|
||||
' Kept: SELECT from printers table (37 printers)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files Modified Summary
|
||||
|
||||
### Total Files Updated: 11
|
||||
|
||||
| File | Type | Changes |
|
||||
|------|------|---------|
|
||||
| check_all_warranties.asp | Utility | machines table, warranties table |
|
||||
| check_all_warranties_clean.asp | Utility | machines table, warranties table |
|
||||
| check_warranties_v2.asp | Utility | machines table, warranties table |
|
||||
| editdevice.asp | Form | machines table queries |
|
||||
| savedevice.asp | Processor | machines table INSERT |
|
||||
| savedevice_direct.asp | Processor | machines table INSERT |
|
||||
| updatepc_direct.asp | Processor | machines table UPDATE |
|
||||
| displaypcs.asp | Display | dateadded → lastupdated |
|
||||
| displaypc.asp | Display | dateadded removed |
|
||||
| displaymachine.asp | Display | dateadded removed |
|
||||
| displaysubnet.asp | Utility | communications table |
|
||||
| network_map.asp | Display | Phase 3 query removed |
|
||||
|
||||
---
|
||||
|
||||
## Manual Database Changes Summary
|
||||
|
||||
### Tables Created
|
||||
- `pc_to_machine_id_mapping` (221 records)
|
||||
|
||||
### Tables Populated
|
||||
- `machines` (+224 PC records)
|
||||
- `communications` (+705 network interface records)
|
||||
- `comstypes` (8 communication types)
|
||||
- `machinetypes` (+5 PC types: 28-32)
|
||||
|
||||
### Columns Added to machines Table
|
||||
```sql
|
||||
ALTER TABLE machines ADD COLUMN pctypeid INT(11);
|
||||
ALTER TABLE machines ADD COLUMN loggedinuser VARCHAR(100);
|
||||
ALTER TABLE machines ADD COLUMN machinestatusid INT(11);
|
||||
ALTER TABLE machines ADD COLUMN lastupdated DATETIME;
|
||||
```
|
||||
|
||||
### Columns NOT Added (User Decision)
|
||||
- `dateadded` - User requested NOT to add this column
|
||||
|
||||
---
|
||||
|
||||
## Verification Results
|
||||
|
||||
### Database Verification
|
||||
|
||||
```sql
|
||||
-- PCs in machines table
|
||||
SELECT COUNT(*) FROM machines WHERE pctypeid IS NOT NULL;
|
||||
-- Result: 224 PCs
|
||||
|
||||
-- Network interfaces in communications
|
||||
SELECT COUNT(*) FROM communications WHERE comstypeid = 1;
|
||||
-- Result: 705 interfaces
|
||||
|
||||
-- PC-to-machine mappings
|
||||
SELECT COUNT(*) FROM pc_to_machine_id_mapping;
|
||||
-- Result: 221 mappings
|
||||
|
||||
-- Old pc table (should still have records - not deleted)
|
||||
SELECT COUNT(*) FROM pc WHERE isactive = 1;
|
||||
-- Result: 276 PCs (preserved as backup)
|
||||
```
|
||||
|
||||
### Page Verification (from logs)
|
||||
|
||||
All pages tested and working:
|
||||
- displaypcs.asp - HTTP 200 (18:52:35)
|
||||
- displaypc.asp - HTTP 200 (18:52:42)
|
||||
- displaymachines.asp - HTTP 200 (18:32:48)
|
||||
- displaymachine.asp - HTTP 200 (after dateadded fix)
|
||||
- network_map.asp - HTTP 200 (17:57:57)
|
||||
|
||||
---
|
||||
|
||||
## Issues Encountered and Resolutions
|
||||
|
||||
### Issue 1: Missing pctypeid Column
|
||||
**Error:** `Unknown column 'machines.pctypeid' in 'where clause'`
|
||||
**Resolution:** Added column manually with `ALTER TABLE`
|
||||
**Root Cause:** Phase 1 script 02_extend_machines_table.sql not run on dev
|
||||
|
||||
### Issue 2: Missing dateadded Column References
|
||||
**Error:** `Unknown column 'machines.dateadded' in 'field list'`
|
||||
**Resolution:** Changed all references to `lastupdated` or removed
|
||||
**Root Cause:** User decided not to add dateadded column, only lastupdated
|
||||
|
||||
### Issue 3: Empty Mapping Table
|
||||
**Error:** Network interface migration found 0 mappings
|
||||
**Resolution:** Manually populated pc_to_machine_id_mapping table
|
||||
**Root Cause:** Duplicate hostnames prevented automatic mapping
|
||||
|
||||
### Issue 4: Duplicate Hostnames
|
||||
**Error:** pcid 59 and 164 both had hostname "G5G9S624ESF"
|
||||
**Resolution:** Used MIN(machineid) to select first match
|
||||
**Impact:** 3 PCs unmapped (224 migrated but only 221 mapped)
|
||||
|
||||
---
|
||||
|
||||
## Production Migration Recommendations
|
||||
|
||||
### Before Running on Production:
|
||||
|
||||
1. **Update Phase 1 Script 02:**
|
||||
- Ensure `02_extend_machines_table.sql` adds these columns:
|
||||
- pctypeid
|
||||
- loggedinuser
|
||||
- machinestatusid
|
||||
- lastupdated (NOT dateadded)
|
||||
|
||||
2. **Update Phase 2 Script 01:**
|
||||
- Add validation check for duplicate hostnames
|
||||
- Add error handling for mapping table population
|
||||
- Consider adding UNIQUE constraint on hostname (if business rules allow)
|
||||
|
||||
3. **Pre-Migration Validation:**
|
||||
```sql
|
||||
-- Check for duplicate hostnames
|
||||
SELECT hostname, COUNT(*)
|
||||
FROM pc
|
||||
WHERE isactive = 1
|
||||
GROUP BY hostname
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
-- Should return 0 rows, or document exceptions
|
||||
```
|
||||
|
||||
4. **Update All 11 ASP Files** on production:
|
||||
- Use the updated versions from dev
|
||||
- Test each file after deployment
|
||||
- Monitor logs for errors
|
||||
|
||||
5. **Plan for Rollback:**
|
||||
- Keep `pc` and `pc_network_interfaces` tables for 30 days
|
||||
- Take full database backup before migration
|
||||
- Document rollback procedure
|
||||
|
||||
---
|
||||
|
||||
## Scripts That Need Updates for Production
|
||||
|
||||
### /sql/migration_phase1/02_extend_machines_table.sql
|
||||
|
||||
**Add these columns:**
|
||||
```sql
|
||||
-- Add PC-specific columns
|
||||
ALTER TABLE machines ADD COLUMN pctypeid INT(11) AFTER machinetypeid;
|
||||
ALTER TABLE machines ADD COLUMN loggedinuser VARCHAR(100) AFTER hostname;
|
||||
ALTER TABLE machines ADD COLUMN machinestatusid INT(11) AFTER osid;
|
||||
ALTER TABLE machines ADD COLUMN lastupdated DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
ON UPDATE CURRENT_TIMESTAMP;
|
||||
|
||||
-- Add indexes for performance
|
||||
ALTER TABLE machines ADD INDEX idx_pctypeid (pctypeid);
|
||||
ALTER TABLE machines ADD INDEX idx_machinestatusid (machinestatusid);
|
||||
```
|
||||
|
||||
### NEW: /sql/migration_phase2/05b_migrate_pc_controls_relationships.sql
|
||||
|
||||
**Create this new script to migrate PC-to-equipment relationships:**
|
||||
|
||||
```sql
|
||||
-- =====================================================
|
||||
-- SCRIPT 05b: Migrate PC Controls Relationships
|
||||
-- =====================================================
|
||||
-- Purpose: Create Controls relationships from pc.machinenumber
|
||||
-- =====================================================
|
||||
|
||||
USE shopdb;
|
||||
|
||||
-- Create Controls relationships
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT DISTINCT
|
||||
equipment.machineid AS equipment_machineid,
|
||||
pc_migrated.machineid AS pc_machineid,
|
||||
3 AS relationshiptypeid, -- 'Controls' relationship
|
||||
1 AS isactive
|
||||
FROM pc old_pc
|
||||
JOIN machines equipment ON equipment.machinenumber = old_pc.machinenumber
|
||||
JOIN machines pc_migrated ON pc_migrated.hostname = old_pc.hostname
|
||||
WHERE old_pc.isactive = 1
|
||||
AND old_pc.machinenumber IS NOT NULL
|
||||
AND old_pc.machinenumber != ''
|
||||
AND equipment.pctypeid IS NULL -- Equipment only
|
||||
AND pc_migrated.pctypeid IS NOT NULL -- PCs only
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships mr
|
||||
WHERE mr.machineid = equipment.machineid
|
||||
AND mr.related_machineid = pc_migrated.machineid
|
||||
AND mr.relationshiptypeid = 3
|
||||
);
|
||||
|
||||
-- Verification
|
||||
SELECT CONCAT('Created ', ROW_COUNT(), ' Controls relationships') AS result;
|
||||
|
||||
SELECT COUNT(*) AS total_relationships FROM machinerelationships;
|
||||
```
|
||||
|
||||
**This script should be run AFTER 01_migrate_pcs_to_machines.sql**
|
||||
|
||||
### /sql/migration_phase2/01_migrate_pcs_to_machines.sql
|
||||
|
||||
**Fix Step 7 - Mapping Table Population:**
|
||||
```sql
|
||||
-- Enhanced mapping with duplicate handling
|
||||
INSERT INTO pc_to_machine_id_mapping (pcid, old_hostname, new_machineid, new_machinenumber)
|
||||
SELECT p.pcid,
|
||||
p.hostname,
|
||||
MIN(m.machineid) AS new_machineid, -- Handle duplicates
|
||||
MIN(m.machinenumber) AS new_machinenumber
|
||||
FROM pc p
|
||||
JOIN machines m ON m.hostname = p.hostname
|
||||
WHERE p.isactive = 1
|
||||
AND m.pctypeid IS NOT NULL
|
||||
GROUP BY p.pcid, p.hostname;
|
||||
|
||||
-- Validate mapping
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM pc WHERE isactive = 1) AS pcs_to_migrate,
|
||||
(SELECT COUNT(*) FROM pc_to_machine_id_mapping) AS pcs_mapped,
|
||||
(SELECT COUNT(*) FROM pc WHERE isactive = 1) -
|
||||
(SELECT COUNT(*) FROM pc_to_machine_id_mapping) AS unmapped_count;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Timeline - Actual
|
||||
|
||||
| Phase | Estimated | Actual | Notes |
|
||||
|-------|-----------|--------|-------|
|
||||
| Pre-migration analysis | 1 hour | 1.5 hours | Found schema discrepancies |
|
||||
| Add missing columns | 5 min | 15 min | Manual ALTER TABLE statements |
|
||||
| Run Phase 1 scripts | 5 min | 10 min | Partial re-run required |
|
||||
| Run Phase 2 script 01 | 10 min | 20 min | Mapping table fix required |
|
||||
| Run Phase 2 script 02 | 5 min | 5 min | Successful |
|
||||
| Update ASP pages | 2 hours | 3 hours | Found 7 additional files |
|
||||
| Testing and fixes | 1 hour | 1.5 hours | Fixed dateadded issues |
|
||||
| **Total** | **4-5 hours** | **~7 hours** | Manual interventions added time |
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria - All Met
|
||||
|
||||
- All 224 PCs migrated to machines table
|
||||
- All 705 network interfaces in communications table
|
||||
- PC list page displays correctly
|
||||
- Individual PC pages load without errors
|
||||
- Network interfaces show properly (IP and MAC addresses)
|
||||
- No "Item cannot be found" errors
|
||||
- All functionality matches machine pages
|
||||
- Security maintained (parameterized queries)
|
||||
- No data loss
|
||||
- Old tables preserved as backup
|
||||
|
||||
---
|
||||
|
||||
## Step 8: Cleanup Migration Tables
|
||||
|
||||
**Date:** November 13, 2025
|
||||
|
||||
**Purpose:** Remove unused backup and mapping tables to clean up database after successful migration.
|
||||
|
||||
**Script Used:**
|
||||
```bash
|
||||
mysql -u570005354 -p shopdb < sql/migration_phase2/07_cleanup_migration_tables.sql
|
||||
```
|
||||
|
||||
**Tables Dropped:**
|
||||
|
||||
1. **Backup Tables** (created during migration for rollback):
|
||||
- `pc_backup_phase2` (276 rows, 0.08 MB)
|
||||
- `pc_network_interfaces_backup_phase2` (705 rows, 0.08 MB)
|
||||
- `pc_comm_config_backup_phase2` (502 rows, 0.34 MB)
|
||||
- `pc_dualpath_assignments_backup_phase2` (33 rows, 0.02 MB)
|
||||
- `pc_model_backup` (206 rows, 0.02 MB)
|
||||
|
||||
2. **Helper/Mapping Tables** (no longer needed):
|
||||
- `pc_to_machine_id_mapping` (221 rows, 0.03 MB) - Used during migration to track old pcid → new machineid
|
||||
- `machine_pc_relationships` (0 rows, 0.06 MB) - Never used, replaced by `machinerelationships`
|
||||
|
||||
**Total Space Freed:** ~0.63 MB
|
||||
|
||||
**Verification:**
|
||||
```sql
|
||||
-- Confirmed essential tables still exist
|
||||
SELECT COUNT(*) FROM machines; -- 483 records (224 PCs + 259 equipment)
|
||||
SELECT COUNT(*) FROM communications; -- 705 records
|
||||
SELECT COUNT(*) FROM machinerelationships; -- 210 records (148 Controls + 62 Dualpath)
|
||||
```
|
||||
|
||||
**Tables Retained** (may still have historical value):
|
||||
- `pc` - Original PC table (kept for historical queries if needed)
|
||||
- `pc_network_interfaces` - Old network config
|
||||
- `pc_comm_config` - Old communication config
|
||||
- `pc_dualpath_assignments` - Old dualpath data
|
||||
- `pc_dnc_config` - DNC configuration (still in use)
|
||||
- `pctype` - PC type reference table (still in use)
|
||||
|
||||
**Note:** The old `pc` and related tables can be dropped in a future cleanup once we confirm no historical queries need them.
|
||||
|
||||
---
|
||||
|
||||
## Next Steps for Production
|
||||
|
||||
1. **Update migration scripts** based on lessons learned
|
||||
2. **Test updated scripts** on dev backup database
|
||||
3. **Create production deployment plan** with maintenance window
|
||||
4. **Prepare rollback procedure** with tested commands
|
||||
5. **Schedule production migration** (estimated 1-2 hours downtime)
|
||||
6. **Deploy updated ASP pages** immediately after migration
|
||||
7. **Monitor logs** for 24-48 hours post-migration
|
||||
8. **Document any production-specific issues**
|
||||
|
||||
---
|
||||
|
||||
## Related Documentation
|
||||
|
||||
- `/home/camp/projects/windows/shopdb/PHASE2_PC_MIGRATION_COMPLETE.md` - Completion summary
|
||||
- `/home/camp/projects/windows/shopdb/sql/migration_phase1/README.md` - Phase 1 scripts
|
||||
- `/home/camp/projects/windows/shopdb/sql/migration_phase2/README.md` - Phase 2 scripts
|
||||
- `/home/camp/projects/ENVIRONMENT_DOCUMENTATION.md` - Dev environment setup
|
||||
|
||||
---
|
||||
|
||||
**Created:** 2025-11-13
|
||||
**Author:** Claude Code + Human
|
||||
**Status:** DEV MIGRATION COMPLETE
|
||||
**Production Status:** PENDING - Scripts need updates based on dev lessons learned
|
||||
Reference in New Issue
Block a user