- 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>
15 KiB
15 KiB
Phase 3: Network Devices Migration to machines Table
Date: 2025-11-10 Status: PLANNING Follows: Phase 2 (PC Migration - Completed)
Executive Summary
Consolidate all network infrastructure devices (servers, switches, cameras, access points, IDFs) into the unified machines table. This completes the infrastructure unification started in Phase 2 with PCs, creating a single source of truth for all physical assets except printers.
Scope
Migrate INTO machines Table:
- Servers → machinetypeid 30
- Switches → machinetypeid 31
- Cameras → machinetypeid 32
- Access Points → machinetypeid 33
- IDFs → machinetypeid 34
- Routers → machinetypeid 35 (if exists)
- Firewalls → machinetypeid 36 (if exists)
Keep SEPARATE:
- Printers → Stay in
printerstable (unique fields, workflows, APIs)
Why This Migration?
Current Problems:
- Data Fragmentation: Network devices scattered across 5+ tables
- Code Duplication: Separate pages for each device type
- Relationship Limitations: Can't relate servers to switches to cameras
- Query Complexity: UNION queries to find all devices on a network
- Inconsistent UI/UX: Different interfaces for similar devices
After Migration:
- Single Source of Truth: All infrastructure in
machinestable - Unified Relationships: Camera → Switch → IDF using
machinerelationships - Unified Communications: All IPs in
communicationstable - Consistent UI: One set of pages for all devices
- Powerful Queries: Cross-device reports and topology mapping
- Better Compliance: All devices tracked in one place
Architecture
Current Structure:
machines table
├── Equipment (machinetypeid 1-24, pctypeid IS NULL)
└── PCs (machinetypeid 25-29, pctypeid IS NOT NULL)
servers table (separate)
switches table (separate)
cameras table (separate)
accesspoints table (separate)
idfs table (separate)
printers table (stays separate)
Target Structure:
machines table
├── Equipment (machinetypeid 1-24, pctypeid IS NULL)
├── PCs (machinetypeid 25-29, pctypeid IS NOT NULL)
└── Network Devices (machinetypeid 30-36, pctypeid IS NULL) ← NEW
printers table (stays separate - by design)
New Machine Types (30-36)
INSERT INTO machinetypes (machinetypeid, machinetype, category, description, displayorder) VALUES
(30, 'Server', 'Network', 'Physical or virtual server', 30),
(31, 'Switch', 'Network', 'Network switch', 31),
(32, 'Camera', 'Network', 'IP camera or security camera', 32),
(33, 'Access Point', 'Network', 'Wireless access point', 33),
(34, 'IDF', 'Network', 'Intermediate Distribution Frame', 34),
(35, 'Router', 'Network', 'Network router', 35),
(36, 'Firewall', 'Network', 'Network firewall', 36);
Filtering Strategy
-- All PCs
SELECT * FROM machines WHERE pctypeid IS NOT NULL;
-- All Equipment (CNC machines, mills, lathes, etc.)
SELECT * FROM machines WHERE pctypeid IS NULL AND machinetypeid BETWEEN 1 AND 24;
-- All Network Devices
SELECT * FROM machines WHERE pctypeid IS NULL AND machinetypeid BETWEEN 30 AND 36;
-- Specific device types
SELECT * FROM machines WHERE machinetypeid = 30; -- Servers
SELECT * FROM machines WHERE machinetypeid = 31; -- Switches
SELECT * FROM machines WHERE machinetypeid = 32; -- Cameras
-- All non-printer infrastructure
SELECT * FROM machines; -- Everything except printers
Data Migration Mapping
Servers Table → Machines
servers.serverid → machines.machineid (new)
servers.modelid → machines.modelnumberid
servers.serialnumber → machines.serialnumber
servers.description → machines.alias
servers.maptop → machines.maptop
servers.mapleft → machines.mapleft
servers.isactive → machines.isactive
servers.ipaddress → communications.address (comstypeid=1)
30 (constant) → machines.machinetypeid
NULL → machines.pctypeid
'SERVER-{serverid}' → machines.machinenumber (generated)
Switches Table → Machines
switches.switchid → machines.machineid (new)
switches.modelid → machines.modelnumberid
switches.serialnumber → machines.serialnumber
switches.description → machines.alias
switches.maptop → machines.maptop
switches.mapleft → machines.mapleft
switches.isactive → machines.isactive
switches.ipaddress → communications.address (comstypeid=1)
31 (constant) → machines.machinetypeid
NULL → machines.pctypeid
'SWITCH-{switchid}' → machines.machinenumber (generated)
Cameras Table → Machines
cameras.cameraid → machines.machineid (new)
cameras.modelid → machines.modelnumberid
cameras.serialnumber → machines.serialnumber
cameras.description → machines.alias
cameras.maptop → machines.maptop
cameras.mapleft → machines.mapleft
cameras.isactive → machines.isactive
cameras.ipaddress → communications.address (comstypeid=1)
32 (constant) → machines.machinetypeid
NULL → machines.pctypeid
'CAMERA-{cameraid}' → machines.machinenumber (generated)
Access Points Table → Machines (if exists)
accesspoints.accesspointid → machines.machineid (new)
accesspoints.modelid → machines.modelnumberid
accesspoints.serialnumber → machines.serialnumber
accesspoints.description → machines.alias
accesspoints.maptop → machines.maptop
accesspoints.mapleft → machines.mapleft
accesspoints.isactive → machines.isactive
accesspoints.ipaddress → communications.address (comstypeid=1)
33 (constant) → machines.machinetypeid
NULL → machines.pctypeid
'AP-{accesspointid}' → machines.machinenumber (generated)
IDFs Table → Machines (if exists)
idfs.idfid → machines.machineid (new)
idfs.name → machines.machinenumber
idfs.description → machines.alias
idfs.maptop → machines.maptop
idfs.mapleft → machines.mapleft
idfs.isactive → machines.isactive
34 (constant) → machines.machinetypeid
NULL → machines.pctypeid
New Relationship Types
INSERT INTO relationshiptypes (relationshiptype, description, isbidirectional) VALUES
-- Existing relationships
('Dualpath', 'Machines sharing the same controller', 1),
('Controlled By', 'Machine controlled by PC', 0),
('Controls', 'PC controls this machine', 0),
-- New network relationships
('Connected To', 'Device physically connected to infrastructure', 0),
('Powered By', 'Device powered by this power source', 0),
('Mounted In', 'Device mounted in rack/cabinet', 0),
('Feeds Video To', 'Camera feeds video to this server/NVR', 0),
('Provides Network', 'Infrastructure provides network to device', 0);
Migration Scripts Structure
/home/camp/projects/windows/shopdb/sql/migration_phase3/
├── 01_create_network_machinetypes.sql
├── 02_migrate_servers_to_machines.sql
├── 03_migrate_switches_to_machines.sql
├── 04_migrate_cameras_to_machines.sql
├── 05_migrate_accesspoints_to_machines.sql
├── 06_migrate_idfs_to_machines.sql
├── 07_migrate_network_communications.sql
├── 08_create_network_relationships.sql
├── 09_update_views_for_network_devices.sql
├── 10_update_vendor_flags.sql
├── VERIFY_PHASE3_MIGRATION.sql
├── RUN_ALL_PHASE3_SCRIPTS.sql
└── ROLLBACK_PHASE3.sql
Migration Order
Pre-Migration:
- Backup database
- Verify Phase 2 is stable
- Document current table structures
- Count records in each table
Migration Steps:
- Create new machinetypes (30-36)
- Migrate servers → machines + communications
- Migrate switches → machines + communications
- Migrate cameras → machines + communications
- Migrate access points → machines + communications (if exists)
- Migrate IDFs → machines (if exists)
- Create network relationships (camera → switch → IDF)
- Update vendor flags (isserver, isswitch, etc.)
- Update views (create vw_network_devices if needed)
- Verify data integrity
Post-Migration:
- Run verification queries
- Test UI pages
- Update code references
- Keep old tables temporarily (for rollback safety)
- Monitor for issues
- Drop old tables after 30 days (if stable)
Code Updates Required
Pages to Update:
- displaymachines.asp - Add filter tabs for network devices
- displaymachine.asp - Already supports all types via machinetypeid
- machine_edit.asp - Already supports all types
- adddevice.asp - Update to include network device types
Pages to Deprecate:
- displayservers.asp → Redirect to displaymachines.asp?type=server
- displayswitches.asp → Redirect to displaymachines.asp?type=switch
- displaycameras.asp → Redirect to displaymachines.asp?type=camera
- network_devices.asp → Redirect to displaymachines.asp?category=network
Views to Update:
-- Update or create
CREATE OR REPLACE VIEW vw_all_infrastructure AS
SELECT
m.machineid,
m.machinenumber,
m.alias,
mt.machinetype,
mt.category,
mo.modelnumber,
v.vendor,
c.address AS ipaddress,
CASE
WHEN m.pctypeid IS NOT NULL THEN 'PC'
WHEN mt.category = 'Network' THEN 'Network Device'
ELSE 'Equipment'
END AS device_category
FROM machines m
LEFT JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1
WHERE m.isactive = 1;
Verification Queries
Record Counts
-- Before migration
SELECT 'servers' AS table_name, COUNT(*) AS count FROM servers
UNION ALL
SELECT 'switches', COUNT(*) FROM switches
UNION ALL
SELECT 'cameras', COUNT(*) FROM cameras
UNION ALL
SELECT 'accesspoints', COUNT(*) FROM accesspoints
UNION ALL
SELECT 'idfs', COUNT(*) FROM idfs;
-- After migration
SELECT
mt.machinetype,
COUNT(*) AS count
FROM machines m
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
WHERE mt.machinetypeid BETWEEN 30 AND 36
GROUP BY mt.machinetype;
Data Integrity
-- Verify all network devices have machine types
SELECT COUNT(*) FROM machines
WHERE machinetypeid BETWEEN 30 AND 36
AND machinetypeid IS NULL;
-- Should be 0
-- Verify all network devices have pctypeid = NULL
SELECT COUNT(*) FROM machines
WHERE machinetypeid BETWEEN 30 AND 36
AND pctypeid IS NOT NULL;
-- Should be 0
-- Verify IP addresses migrated
SELECT
mt.machinetype,
COUNT(DISTINCT m.machineid) AS total_devices,
COUNT(DISTINCT c.machineid) AS devices_with_ip
FROM machines m
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
LEFT JOIN communications c ON m.machineid = c.machineid AND c.comstypeid = 1
WHERE mt.machinetypeid BETWEEN 30 AND 36
GROUP BY mt.machinetype;
Rollback Plan
If Issues Found:
- Stop immediately
- Run ROLLBACK_PHASE3.sql
- Verify old tables intact
- Restore from backup if needed
- Review errors
- Fix and retry
Rollback Script (High-Level):
-- Delete migrated network devices from machines
DELETE FROM machines WHERE machinetypeid BETWEEN 30 AND 36;
-- Delete migrated communications
DELETE FROM communications WHERE machineid NOT IN (SELECT machineid FROM machines);
-- Delete new relationship types
DELETE FROM relationshiptypes WHERE relationshiptypeid > 5;
-- Delete new machinetypes
DELETE FROM machinetypes WHERE machinetypeid BETWEEN 30 AND 36;
-- Verify old tables still have data
SELECT COUNT(*) FROM servers;
SELECT COUNT(*) FROM switches;
SELECT COUNT(*) FROM cameras;
Success Criteria
Migration Successful If:
- All records migrated (counts match)
- All IP addresses migrated to communications
- All relationships preserved
- No NULL values in required fields
- UI pages display correctly
- Queries perform well
- No data loss
- Rollback tested and works
Timeline Estimate
- Planning & Script Creation: 2-3 hours
- Testing on Dev/Backup: 1-2 hours
- Production Migration: 30-45 minutes
- Verification: 1 hour
- Code Updates: 3-4 hours
- Testing & Bug Fixes: 2-3 hours
Total: ~10-15 hours of work
Risk Assessment
Low Risk:
- Pattern proven with Phase 2 PC migration
- Can be rolled back easily
- Old tables kept temporarily
- Comprehensive verification
Medium Risk:
- Multiple tables being migrated
- Code references to update
- Testing required for all device types
Mitigation:
- Test on backup database first
- Migrate one device type at a time
- Verify after each migration
- Keep old tables for 30 days
- Update code incrementally
Benefits After Completion
Immediate:
- Single query for all infrastructure
- Unified relationship management
- Camera → IDF relationships work
- Consistent UI across all devices
- Better network topology visibility
Long-Term:
- Easier to add new device types
- Less code duplication
- Better reporting capabilities
- Simplified maintenance
- CMDB-style asset management
- Better compliance tracking
Next Steps
- Create migration SQL scripts
- Create verification scripts
- Create rollback scripts
- Test on backup database
- Review and approve plan
- Schedule migration window
- Execute migration
- Update code
- Monitor and verify
Status: Ready for script creation Approval Required: Yes Backup Required: Yes Estimated Duration: 30-45 minutes (migration only)
Questions to Answer Before Migration
- Do accesspoints and idfs tables exist?
- Are there any custom fields in device tables we need to preserve?
- Are there any foreign key constraints to old tables?
- What's the maintenance window schedule?
- Should we create camera → IDF relationships during migration or manually after?
Ready to proceed with script creation!