diff --git a/sql/consolidate_pc_machinetypes.sql b/sql/consolidate_pc_machinetypes.sql new file mode 100644 index 0000000..ef838f4 --- /dev/null +++ b/sql/consolidate_pc_machinetypes.sql @@ -0,0 +1,44 @@ +-- Consolidate PC Machine Types +-- Date: 2025-12-08 +-- +-- Previously PCs used multiple machinetypeids: +-- 33: Standard PC +-- 34: Engineering PC +-- 35: Shopfloor PC +-- 42: PC - Wax Trace +-- 43: PC - Measuring Tool +-- +-- Now all PCs use machinetypeid 33 (PC) with pctypeid for sub-type + +-- Add new PC types +INSERT IGNORE INTO pctype (typename, description, functionalaccountid, isactive, displayorder) VALUES +('Keyence', 'Keyence measurement system', 1, 1, 6), +('Genspect', 'Genspect inspection system', 1, 1, 7), +('Heat Treat', 'Heat treat monitoring', 1, 1, 8); + +-- Rename machinetypeid 33 to just 'PC' +UPDATE machinetypes SET machinetype = 'PC' WHERE machinetypeid = 33; + +-- Update pctypeid based on current machinetypeid +-- 34 (Engineering PC) -> pctypeid 2 (Engineer) +UPDATE machines SET pctypeid = 2 WHERE machinetypeid = 34 AND (pctypeid IS NULL OR pctypeid = 1); + +-- 35 (Shopfloor PC) -> pctypeid 3 (Shopfloor) +UPDATE machines SET pctypeid = 3 WHERE machinetypeid = 35 AND (pctypeid IS NULL OR pctypeid = 1); + +-- 42 (PC - Wax Trace) -> pctypeid 6 (Wax / Trace) +UPDATE machines SET pctypeid = 6 WHERE machinetypeid = 42 AND (pctypeid IS NULL OR pctypeid = 1); + +-- 43 (PC - Measuring Tool) -> pctypeid 7 (Keyence) +UPDATE machines SET pctypeid = 7 WHERE machinetypeid = 43 AND (pctypeid IS NULL OR pctypeid = 1); + +-- Consolidate all PCs to machinetypeid 33 +UPDATE machines SET machinetypeid = 33 WHERE machinetypeid IN (34, 35, 42, 43); + +-- Verification query +-- SELECT pt.pctypeid, pt.typename, COUNT(*) as count +-- FROM machines m +-- JOIN pctype pt ON m.pctypeid = pt.pctypeid +-- WHERE m.pctypeid IS NOT NULL +-- GROUP BY pt.pctypeid, pt.typename +-- ORDER BY pt.pctypeid;