- Strip emojis from 47 markdown files across docs/, sql/, and root - Add docs/DOCS_CONSOLIDATION_PLAN.md with plan to reduce 45 docs to 8 - Establish no-emoji rule for documentation going forward 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 1: Database Schema Migration Scripts
Created: 2025-11-06 Status: Ready for DEV testing Estimated Time: 15-20 minutes
Overview
This directory contains Phase 1 migration scripts for consolidating the pc table into the machines table. These scripts create new infrastructure tables and extend existing tables to support both PCs and machines in a unified schema.
Scripts Included
Migration Scripts (Run in Order)
-
01_create_communications_infrastructure.sql (2-3 min)
- Creates
comstypestable (8 communication types) - Creates
communicationstable (generic address field)
- Creates
-
02_extend_machines_table.sql (2-3 min)
- Adds 11 new columns to machines table
- Adds indexes for new columns
-
03_create_pc_machine_types.sql (1 min)
- Creates 5 PC machine types (Standard, Shopfloor, Engineer, Server, Laptop)
-
04_create_warranty_infrastructure.sql (1-2 min)
- Creates
warrantiestable - Creates warranty status views
- Creates
-
05_create_compliance_infrastructure.sql (2-3 min)
- Creates
compliancetable (15 columns) - Creates
compliancescanstable - Creates compliance views
- Creates
-
06_extend_businessunits_table.sql (1 min)
- Adds liaison fields to businessunits
-
07_rename_pcstatus_to_machinestatus.sql (1 min)
- Renames pcstatus table and columns
- Adds FK constraint to machines
-
08_create_machine_relationships_infrastructure.sql (2 min)
- Creates
relationshiptypestable - Creates
machinerelationshipstable - Creates relationship views
- Creates
Rollback Scripts (Reverse Order)
- ROLLBACK_08_machine_relationships_infrastructure.sql
- ROLLBACK_07_machinestatus_rename.sql
- ROLLBACK_06_businessunits_extensions.sql
- ROLLBACK_05_compliance_infrastructure.sql
- ROLLBACK_04_warranty_infrastructure.sql
- ROLLBACK_03_pc_machine_types.sql
- ROLLBACK_02_machines_table_extensions.sql
- ROLLBACK_01_communications_infrastructure.sql
Quick Start
Option 1: Run All Scripts (Recommended for DEV)
# Run master script (executes all 8 in order)
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < RUN_ALL_PHASE1_SCRIPTS.sql
Option 2: Run Individual Scripts
# Run each script one at a time
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < 01_create_communications_infrastructure.sql
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < 02_extend_machines_table.sql
# ... and so on
Option 3: Use MySQL Workbench
- Connect to database
- Open script file
- Execute
- Review output
- Repeat for each script
Pre-Execution Checklist
- Backup created - Full database backup exists
- Dev environment - Running on DEV, not production
- Dependencies - All required tables exist (machines, pctype, operatingsystems, etc.)
- Disk space - At least 100MB free
- Permissions - User has CREATE, ALTER, DROP privileges
Execution Steps
1. Create Backup
# Backup current database
docker exec dev-mysql mysqldump -u 570005354 -p570005354 shopdb > /tmp/shopdb-before-phase1-$(date +%Y%m%d).sql
2. Run Migration Scripts
cd /home/camp/projects/windows/shopdb/sql/migration_phase1
# Option A: Run all at once
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < RUN_ALL_PHASE1_SCRIPTS.sql
# Option B: Run individually for better control
for i in {01..08}; do
echo "Running script $i..."
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < ${i}_*.sql
if [ $? -ne 0 ]; then
echo "ERROR in script $i! Stopping."
exit 1
fi
done
3. Verify Results
# Check new tables were created
docker exec dev-mysql mysql -u 570005354 -p570005354 shopdb -e "SHOW TABLES LIKE '%com%'; SHOW TABLES LIKE '%warrant%'; SHOW TABLES LIKE '%compliance%'; SHOW TABLES LIKE '%relationship%';"
# Check machines table structure
docker exec dev-mysql mysql -u 570005354 -p570005354 shopdb -e "DESCRIBE machines;"
# Check machine types
docker exec dev-mysql mysql -u 570005354 -p570005354 shopdb -e "SELECT * FROM machinetypes WHERE machinetype LIKE 'PC -%';"
4. If Rollback Needed
# Run rollback scripts in REVERSE order (08 down to 01)
for i in {08..01}; do
echo "Rolling back script $i..."
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb < ROLLBACK_${i}_*.sql
done
Tables Created
New Tables (7)
- comstypes - Communication types (IP, Serial, etc.)
- communications - Generic communications (replaces pc_comm_config + pc_network_interfaces)
- warranties - Warranty tracking
- compliance - Compliance and security tracking
- compliancescans - Historical scan records
- relationshiptypes - Types of machine relationships
- machinerelationships - Machine-to-machine relationships
Modified Tables (3)
- machines - Added 11 columns (hostname, serialnumber, osid, etc.)
- businessunits - Added 2 columns (liaisonname, liaisonsso)
- machinestatus - Renamed from pcstatus
New Columns in machines Table
- hostname (VARCHAR 100)
- loggedinuser (VARCHAR 100)
- serialnumber (VARCHAR 100)
- osid (INT 11) - FK to operatingsystems
- machinestatusid (INT 11) - FK to machinestatus
- pctypeid (INT 11) - FK to pctype
- controllertypeid (INT 11) - FK to controllertypes
- controllerosid (INT 11) - FK to operatingsystems
- requires_manual_machine_config (TINYINT 1)
- lastupdated (DATETIME)
- dateadded (DATETIME)
Views Created
- vw_warranty_status
- vw_warranties_expiring
- vw_compliance_summary
- vw_machine_relationships
- vw_dualpath_machines
Testing Checklist
After running scripts, verify:
- All 7 new tables exist
- machines table has 11 new columns
- 5 PC machine types created
- machinestatus table exists (pcstatus renamed)
- All views created successfully
- No errors in execution
- Foreign keys in place
- Indexes created
Common Issues
Issue: FK constraint fails
Cause: Referenced table doesn't exist yet Fix: Run scripts in order (01 through 08)
Issue: Column already exists
Cause: Script already ran Fix: Safe to ignore or run rollback first
Issue: Permission denied
Cause: User lacks privileges Fix: Grant CREATE, ALTER, DROP privileges
Next Steps After Phase 1
- Test queries - Verify new tables work
- Phase 2 - Data migration scripts (PC → machines)
- Phase 3 - Update views that reference pc table
- Phase 4 - Update ASP files
Support
Documentation:
- Main design doc:
PC_MACHINES_CONSOLIDATION_PLAN.md - Status summary:
MIGRATION_STATUS_SUMMARY.md - Quick reference:
MIGRATION_QUICK_REFERENCE.md
Questions?
- Review design documents
- Check CRITICAL_RULES.md
- Test on DEV first!
Notes
- REVERSIBLE: All scripts have rollback scripts
- SAFE: No data deletion (only schema changes)
- TESTED: Design complete, ready for dev testing
- ESTIMATED TIME: 15-20 minutes total
Created: 2025-11-06 Last Updated: 2025-11-06 Status: Ready for DEV testing