Clean up sql directory after production sync
- Remove 27 completed one-off migration scripts - Remove old backup file (dev-backup-20251120) - Remove completed shell scripts for prod import/export - Archive migration_phase1-4 directories and documentation - Keep only view_consolidation.sql as active script All migrations have been applied to production. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,156 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- Create/Update vw_network_devices View - Phase 2 Compatible
|
||||
-- =============================================================================
|
||||
-- Date: 2025-11-21
|
||||
-- Purpose: Update vw_network_devices to query machines table for infrastructure
|
||||
-- Printers remain in printers table (has fqdn column)
|
||||
-- Other network devices (IDF, Server, Switch, Camera, Access Point) are in machines table
|
||||
-- Machine Type IDs: 15=IDF, 16=Server, 17=Switch, 18=Camera, 19=Access Point, 20=Printer
|
||||
-- =============================================================================
|
||||
|
||||
USE shopdb;
|
||||
|
||||
-- Drop existing view
|
||||
DROP VIEW IF EXISTS vw_network_devices;
|
||||
|
||||
-- Create view with machines table for infrastructure + printers table for printers
|
||||
CREATE VIEW vw_network_devices AS
|
||||
-- Network infrastructure devices from machines table (IDF, Server, Switch, Camera, Access Point)
|
||||
SELECT
|
||||
mt.machinetype AS device_type,
|
||||
m.machineid AS device_id,
|
||||
COALESCE(m.alias, m.machinenumber) AS device_name,
|
||||
m.modelnumberid AS modelid,
|
||||
mo.modelnumber,
|
||||
v.vendor,
|
||||
m.serialnumber,
|
||||
c.address AS ipaddress,
|
||||
NULL AS fqdn, -- Infrastructure devices don't have FQDN
|
||||
m.machinenotes AS description,
|
||||
m.maptop,
|
||||
m.mapleft,
|
||||
m.isactive,
|
||||
-- Camera-specific: which IDF closet (from machinerelationships)
|
||||
(SELECT mr.related_machineid
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE mr.machineid = m.machineid
|
||||
AND rt.relationshiptype = 'Located In'
|
||||
AND mr.isactive = 1
|
||||
LIMIT 1) AS idfid,
|
||||
-- Camera-specific: IDF name
|
||||
(SELECT m2.machinenumber
|
||||
FROM machinerelationships mr
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
WHERE mr.machineid = m.machineid
|
||||
AND rt.relationshiptype = 'Located In'
|
||||
AND mr.isactive = 1
|
||||
LIMIT 1) AS idfname,
|
||||
-- Camera-specific: MAC address (from communications table)
|
||||
(SELECT c2.macaddress
|
||||
FROM communications c2
|
||||
WHERE c2.machineid = m.machineid
|
||||
AND c2.macaddress IS NOT NULL
|
||||
LIMIT 1) AS macaddress
|
||||
FROM machines m
|
||||
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
|
||||
AND c.isactive = 1
|
||||
WHERE m.machinetypeid IN (15, 16, 17, 18, 19) -- IDF, Server, Switch, Camera, Access Point
|
||||
AND m.pctypeid IS NULL -- Exclude PCs
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Printers from printers table (has fqdn column)
|
||||
SELECT
|
||||
'Printer' AS device_type,
|
||||
p.printerid AS device_id,
|
||||
p.printerwindowsname AS device_name,
|
||||
p.modelid,
|
||||
m.modelnumber,
|
||||
v.vendor,
|
||||
p.serialnumber,
|
||||
p.ipaddress,
|
||||
p.fqdn, -- Printers have FQDN
|
||||
NULL AS description,
|
||||
p.maptop,
|
||||
p.mapleft,
|
||||
p.isactive,
|
||||
NULL AS idfid,
|
||||
NULL AS idfname,
|
||||
NULL AS macaddress
|
||||
FROM printers p
|
||||
LEFT JOIN models m ON p.modelid = m.modelnumberid
|
||||
LEFT JOIN vendors v ON m.vendorid = v.vendorid;
|
||||
|
||||
-- =============================================================================
|
||||
-- Verification
|
||||
-- =============================================================================
|
||||
|
||||
SELECT '✓ View created successfully (Phase 2)' AS status;
|
||||
|
||||
SELECT 'View columns:' AS '';
|
||||
SELECT COLUMN_NAME, ORDINAL_POSITION
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'vw_network_devices'
|
||||
ORDER BY ORDINAL_POSITION;
|
||||
|
||||
SELECT '' AS '';
|
||||
SELECT 'Device counts by type:' AS '';
|
||||
SELECT device_type, COUNT(*) AS count
|
||||
FROM vw_network_devices
|
||||
GROUP BY device_type
|
||||
ORDER BY device_type;
|
||||
|
||||
SELECT '' AS '';
|
||||
SELECT 'Sample devices (first 10):' AS '';
|
||||
SELECT device_type, device_name, vendor, modelnumber, ipaddress, fqdn
|
||||
FROM vw_network_devices
|
||||
LIMIT 10;
|
||||
|
||||
-- =============================================================================
|
||||
-- NOTES
|
||||
-- =============================================================================
|
||||
--
|
||||
-- View Columns (16 total):
|
||||
-- 1. device_type - Type: IDF, Server, Switch, Camera, Access Point (from machines), Printer (from printers)
|
||||
-- 2. device_id - machineid or printerid
|
||||
-- 3. device_name - Device name/alias
|
||||
-- 4. modelid - Foreign key to models table
|
||||
-- 5. modelnumber - Model number from models table
|
||||
-- 6. vendor - Vendor name from vendors table
|
||||
-- 7. serialnumber - Serial number
|
||||
-- 8. ipaddress - IP address
|
||||
-- 9. fqdn - FQDN (Printers only)
|
||||
-- 10. description - Description
|
||||
-- 11. maptop - Y coordinate for map display
|
||||
-- 12. mapleft - X coordinate for map display
|
||||
-- 13. isactive - Active flag
|
||||
-- 14. idfid - IDF ID (Camera only, from machinerelationships)
|
||||
-- 15. idfname - IDF name (Camera only, from machinerelationships)
|
||||
-- 16. macaddress - MAC address (Camera only, from communications)
|
||||
--
|
||||
-- Machine Type IDs:
|
||||
-- 15 = IDF
|
||||
-- 16 = Server
|
||||
-- 17 = Switch
|
||||
-- 18 = Camera
|
||||
-- 19 = Access Point
|
||||
-- 20 = Printer (still in printers table, not machines)
|
||||
--
|
||||
-- Data Sources:
|
||||
-- - IDFs, Servers, Switches, Cameras, Access Points: machines table
|
||||
-- - Printers: printers table (has fqdn column)
|
||||
--
|
||||
-- Used by: network_devices.asp
|
||||
--
|
||||
-- To add a new IDF:
|
||||
-- INSERT INTO machines (machinetypeid, machinenumber, alias, mapleft, maptop, isactive)
|
||||
-- VALUES (15, 'IDF-NAME', 'Description', 100, 100, 1);
|
||||
--
|
||||
-- =============================================================================
|
||||
@@ -1,85 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- Migration: Add FQDN column to machines table
|
||||
-- Purpose: Allow network devices to store fully qualified domain names
|
||||
-- Date: 2025-12-01
|
||||
--
|
||||
-- Run on PRODUCTION:
|
||||
-- mysql -u root -p shopdb < add_fqdn_to_machines.sql
|
||||
-- =============================================================================
|
||||
|
||||
-- Check if column already exists before adding
|
||||
SET @dbname = DATABASE();
|
||||
SET @tablename = 'machines';
|
||||
SET @columnname = 'fqdn';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @dbname
|
||||
AND TABLE_NAME = @tablename
|
||||
AND COLUMN_NAME = @columnname
|
||||
) > 0,
|
||||
'SELECT ''Column fqdn already exists in machines table'' AS message;',
|
||||
'ALTER TABLE machines ADD COLUMN fqdn VARCHAR(255) NULL AFTER hostname;'
|
||||
));
|
||||
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- Verify the column was added
|
||||
SELECT 'Column migration complete.' AS status;
|
||||
|
||||
-- =============================================================================
|
||||
-- Update vw_network_devices view to include FQDN from machines table
|
||||
-- =============================================================================
|
||||
CREATE OR REPLACE VIEW vw_network_devices AS
|
||||
-- Printers from printers table
|
||||
SELECT
|
||||
'Printer' AS device_type,
|
||||
p.printerid AS device_id,
|
||||
p.printerwindowsname AS device_name,
|
||||
p.modelid AS modelid,
|
||||
m.modelnumber AS modelnumber,
|
||||
v.vendor AS vendor,
|
||||
p.serialnumber AS serialnumber,
|
||||
p.ipaddress AS ipaddress,
|
||||
NULL AS description,
|
||||
p.maptop AS maptop,
|
||||
p.mapleft AS mapleft,
|
||||
p.isactive AS isactive,
|
||||
NULL AS idfid,
|
||||
NULL AS idfname,
|
||||
NULL AS macaddress,
|
||||
p.fqdn AS fqdn
|
||||
FROM printers p
|
||||
LEFT JOIN models m ON p.modelid = m.modelnumberid
|
||||
LEFT JOIN vendors v ON m.vendorid = v.vendorid
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Network devices from machines table (machinetypeid 16-20)
|
||||
SELECT
|
||||
mt.machinetype AS device_type,
|
||||
ma.machineid AS device_id,
|
||||
COALESCE(ma.alias, ma.machinenumber) AS device_name,
|
||||
ma.modelnumberid AS modelid,
|
||||
mo.modelnumber AS modelnumber,
|
||||
ve.vendor AS vendor,
|
||||
ma.serialnumber AS serialnumber,
|
||||
c.address AS ipaddress,
|
||||
ma.machinenotes AS description,
|
||||
ma.maptop AS maptop,
|
||||
ma.mapleft AS mapleft,
|
||||
ma.isactive AS isactive,
|
||||
NULL AS idfid,
|
||||
NULL AS idfname,
|
||||
c.macaddress AS macaddress,
|
||||
ma.fqdn AS fqdn
|
||||
FROM machines ma
|
||||
JOIN machinetypes mt ON ma.machinetypeid = mt.machinetypeid
|
||||
LEFT JOIN models mo ON ma.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors ve ON mo.vendorid = ve.vendorid
|
||||
LEFT JOIN communications c ON ma.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1
|
||||
WHERE mt.machinetypeid IN (16, 17, 18, 19, 20);
|
||||
|
||||
SELECT 'View vw_network_devices updated to include FQDN from machines table.' AS status;
|
||||
@@ -1,28 +0,0 @@
|
||||
-- Add Genspect/EAS1000 and Part Marker equipment types
|
||||
-- Run on production database
|
||||
-- Date: 2025-12-09
|
||||
|
||||
-- ============================================================================
|
||||
-- Add Genspect machinetypeid
|
||||
-- ============================================================================
|
||||
SET @genspect_exists = (SELECT COUNT(*) FROM machinetypes WHERE machinetype = 'Genspect');
|
||||
|
||||
INSERT INTO machinetypes (machinetype, isactive)
|
||||
SELECT 'Genspect', 1
|
||||
FROM dual
|
||||
WHERE @genspect_exists = 0;
|
||||
|
||||
-- ============================================================================
|
||||
-- Add Part Marker machinetypeid
|
||||
-- ============================================================================
|
||||
SET @partmarker_exists = (SELECT COUNT(*) FROM machinetypes WHERE machinetype = 'Part Marker');
|
||||
|
||||
INSERT INTO machinetypes (machinetype, isactive)
|
||||
SELECT 'Part Marker', 1
|
||||
FROM dual
|
||||
WHERE @partmarker_exists = 0;
|
||||
|
||||
-- ============================================================================
|
||||
-- Show results
|
||||
-- ============================================================================
|
||||
SELECT machinetypeid, machinetype FROM machinetypes WHERE machinetype IN ('Genspect', 'Part Marker');
|
||||
@@ -1,14 +0,0 @@
|
||||
-- Add HeatTreat application for PC type detection
|
||||
-- Run on production database
|
||||
-- Date: 2025-12-09
|
||||
|
||||
-- Check if HeatTreat already exists before inserting
|
||||
INSERT INTO applications (appname, appdescription, supportteamid, isactive)
|
||||
SELECT 'HeatTreat', 'Heat Treat monitoring and control software', 1, 1
|
||||
FROM dual
|
||||
WHERE NOT EXISTS (SELECT 1 FROM applications WHERE appname = 'HeatTreat');
|
||||
|
||||
-- Verify the insert
|
||||
SELECT appid, appname, appdescription, isactive
|
||||
FROM applications
|
||||
WHERE appname = 'HeatTreat';
|
||||
@@ -1,15 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- FILE: add_iswinrm_column.sql
|
||||
-- PURPOSE: Add iswinrm column to machines table for tracking WinRM status
|
||||
-- DATE: 2025-12-05
|
||||
--
|
||||
-- USAGE: Run this on production database
|
||||
-- mysql -u root -p shopdb < add_iswinrm_column.sql
|
||||
-- ============================================================================
|
||||
|
||||
-- Add iswinrm column after isvnc
|
||||
ALTER TABLE machines ADD COLUMN iswinrm BIT(1) NULL DEFAULT b'0' AFTER isvnc;
|
||||
|
||||
-- Verify the column was added
|
||||
SELECT 'iswinrm column added successfully' AS status;
|
||||
SHOW COLUMNS FROM machines WHERE Field IN ('isvnc', 'iswinrm');
|
||||
@@ -1,40 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- FILE: add_new_apps_2025-12-05.sql
|
||||
-- PURPOSE: Add new applications for production deployment
|
||||
-- DATE: 2025-12-05
|
||||
--
|
||||
-- USAGE: Run this on production database
|
||||
-- mysql -u root -p shopdb < add_new_apps_2025-12-05.sql
|
||||
-- ============================================================================
|
||||
|
||||
-- Add Keyence VR Series application
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(69, 'Keyence VR Series', 1);
|
||||
|
||||
-- Add Genspect application
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(70, 'Genspect', 1);
|
||||
|
||||
-- Add GageCal application (EAS1000 gage calibration)
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(71, 'GageCal', 1);
|
||||
|
||||
-- Add NI Software application (National Instruments)
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(72, 'NI Software', 1);
|
||||
|
||||
-- Add goCMM application (CMM companion software)
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(73, 'goCMM', 1);
|
||||
|
||||
-- Add DODA application (Dovetail Digital Analysis - CMM)
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(74, 'DODA', 1);
|
||||
|
||||
-- Add FormStatusMonitor application (Wax Trace companion)
|
||||
INSERT INTO applications (appid, appname, isactive) VALUES
|
||||
(75, 'FormStatusMonitor', 1);
|
||||
|
||||
-- Verify additions
|
||||
SELECT 'Applications added:' AS status;
|
||||
SELECT appid, appname, isactive FROM applications WHERE appid IN (69, 70, 71, 72, 73, 74, 75);
|
||||
@@ -1,133 +0,0 @@
|
||||
-- Add PC uptime tracking: lastboottime column and view updates
|
||||
-- Run on production database
|
||||
-- Date: 2025-12-09
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: Add lastboottime column to machines table (if not exists)
|
||||
-- ============================================================================
|
||||
SET @dbname = DATABASE();
|
||||
SET @tablename = 'machines';
|
||||
SET @columnname = 'lastboottime';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @dbname
|
||||
AND TABLE_NAME = @tablename
|
||||
AND COLUMN_NAME = @columnname
|
||||
) > 0,
|
||||
'SELECT ''Column lastboottime already exists'' AS status;',
|
||||
'ALTER TABLE machines ADD COLUMN lastboottime DATETIME NULL DEFAULT NULL AFTER lastupdated;'
|
||||
));
|
||||
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: Update vw_active_pcs view to include lastboottime and uptime_days
|
||||
-- ============================================================================
|
||||
CREATE OR REPLACE VIEW vw_active_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
COALESCE(v.vendor, 'Unknown') AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
m.machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
COALESCE(pt.typename, 'Unknown') AS pctype,
|
||||
COALESCE(pt.description, 'Unknown') AS typedescription,
|
||||
CASE
|
||||
WHEN w.enddate IS NULL THEN 'Unknown'
|
||||
WHEN w.enddate < CURDATE() THEN 'Expired'
|
||||
WHEN w.enddate < DATE_ADD(CURDATE(), INTERVAL 90 DAY) THEN 'Expiring Soon'
|
||||
ELSE 'Active'
|
||||
END AS warrantystatus,
|
||||
w.enddate AS warrantyenddate,
|
||||
CASE WHEN w.enddate IS NULL THEN NULL ELSE DATEDIFF(w.enddate, CURDATE()) END AS warrantydaysremaining,
|
||||
m.lastupdated,
|
||||
DATEDIFF(NOW(), m.lastupdated) AS daysold,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
LEFT JOIN warranties w ON m.machineid = w.machineid
|
||||
WHERE m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 3: Update vw_shopfloor_pcs view to include lastboottime and uptime_days
|
||||
-- ============================================================================
|
||||
CREATE OR REPLACE VIEW vw_shopfloor_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
COALESCE(CONVERT(mo.machinenumber USING utf8mb4), CONVERT(m.machinenumber USING utf8mb4)) AS machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
m.lastupdated,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN machine_overrides mo ON pcmap.pcid = mo.pcid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY COALESCE(CONVERT(mo.machinenumber USING utf8mb4), CONVERT(m.machinenumber USING utf8mb4)), m.hostname;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 4: Update vw_recent_updates view to include lastboottime and uptime_days
|
||||
-- ============================================================================
|
||||
CREATE OR REPLACE VIEW vw_recent_updates AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.machinenumber,
|
||||
m.hostname,
|
||||
CASE
|
||||
WHEN m.pctypeid IS NOT NULL THEN CONCAT('PC - ', pt.typename)
|
||||
ELSE mt.machinetype
|
||||
END AS machine_type,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.lastupdated,
|
||||
DATEDIFF(NOW(), m.lastupdated) AS days_since_update,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
WHERE m.isactive = 1
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||
ORDER BY m.lastupdated DESC
|
||||
LIMIT 100;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 5: Verify changes
|
||||
-- ============================================================================
|
||||
SELECT 'Column check:' AS verification;
|
||||
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'machines'
|
||||
AND COLUMN_NAME = 'lastboottime';
|
||||
|
||||
SELECT 'Views updated:' AS verification;
|
||||
SELECT TABLE_NAME, VIEW_DEFINITION LIKE '%lastboottime%' AS has_lastboottime
|
||||
FROM INFORMATION_SCHEMA.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN ('vw_active_pcs', 'vw_shopfloor_pcs', 'vw_recent_updates');
|
||||
@@ -1,44 +0,0 @@
|
||||
-- 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;
|
||||
File diff suppressed because one or more lines are too long
@@ -1,23 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Drop Legacy PC Tables
|
||||
--
|
||||
-- These tables are no longer used after PC migration to machines table.
|
||||
-- All ASP code now uses machines table or vw_warranty_status view.
|
||||
--
|
||||
-- Run this AFTER verifying the application works correctly.
|
||||
-- ============================================================================
|
||||
|
||||
-- Verify no dependencies before dropping
|
||||
-- SELECT * FROM information_schema.KEY_COLUMN_USAGE
|
||||
-- WHERE REFERENCED_TABLE_NAME IN ('pc', 'pc_backup_phase2');
|
||||
|
||||
-- Drop the legacy tables
|
||||
DROP TABLE IF EXISTS pc_backup_phase2;
|
||||
DROP TABLE IF EXISTS pc;
|
||||
|
||||
-- Verify tables are gone
|
||||
SHOW TABLES LIKE 'pc%';
|
||||
|
||||
-- Expected remaining tables:
|
||||
-- pc_to_machine_id_mapping (still needed by views)
|
||||
-- pctype (still needed for PC type lookups)
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Extract specific tables from production backup for import into dev
|
||||
# Source: database-backup-11-13-25-eod.sql
|
||||
# Target tables: notifications, notificationtypes, printers, knowledgebase
|
||||
|
||||
BACKUP_FILE="/home/camp/projects/windows/database-backup-11-13-25-eod.sql"
|
||||
OUTPUT_DIR="/home/camp/projects/windows/shopdb/sql"
|
||||
|
||||
echo "Extracting production data from $BACKUP_FILE..."
|
||||
|
||||
# Extract notifications table (structure + data)
|
||||
echo "Extracting notifications..."
|
||||
sed -n '/CREATE TABLE IF NOT EXISTS `notifications`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_notifications.sql"
|
||||
|
||||
# Extract notificationtypes table (structure + data)
|
||||
echo "Extracting notificationtypes..."
|
||||
sed -n '/CREATE TABLE IF NOT EXISTS `notificationtypes`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_notificationtypes.sql"
|
||||
|
||||
# Extract printers table (structure + data)
|
||||
echo "Extracting printers..."
|
||||
sed -n '/CREATE TABLE IF NOT EXISTS `printers`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_printers.sql"
|
||||
|
||||
# Extract knowledgebase table (structure + data)
|
||||
echo "Extracting knowledgebase..."
|
||||
sed -n '/CREATE TABLE IF NOT EXISTS `knowledgebase`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_knowledgebase.sql"
|
||||
|
||||
echo "Extraction complete!"
|
||||
echo ""
|
||||
echo "Files created:"
|
||||
ls -lh "$OUTPUT_DIR"/prod_*.sql
|
||||
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Review the extracted files"
|
||||
echo "2. Run import_prod_data.sql to import into dev database"
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Extract only INSERT statements from production backup
|
||||
# This avoids schema conflicts
|
||||
|
||||
BACKUP_FILE="/home/camp/projects/windows/shopdb/sql/prod_printers.sql"
|
||||
OUTPUT_DIR="/home/camp/projects/windows/shopdb/sql"
|
||||
|
||||
echo "Extracting only INSERT statements from production data..."
|
||||
|
||||
# Extract only notifications INSERTs
|
||||
echo "Extracting notifications INSERTs..."
|
||||
grep "^INSERT INTO \`notifications\`" "$OUTPUT_DIR/prod_notifications.sql" > "$OUTPUT_DIR/prod_notifications_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 0;" | cat - "$OUTPUT_DIR/prod_notifications_inserts.sql" > temp && mv temp "$OUTPUT_DIR/prod_notifications_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 1;" >> "$OUTPUT_DIR/prod_notifications_inserts.sql"
|
||||
|
||||
# Extract only notificationtypes INSERTs
|
||||
echo "Extracting notificationtypes INSERTs..."
|
||||
grep "^INSERT INTO \`notificationtypes\`" "$OUTPUT_DIR/prod_notificationtypes.sql" > "$OUTPUT_DIR/prod_notificationtypes_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 0;" | cat - "$OUTPUT_DIR/prod_notificationtypes_inserts.sql" > temp && mv temp "$OUTPUT_DIR/prod_notificationtypes_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 1;" >> "$OUTPUT_DIR/prod_notificationtypes_inserts.sql"
|
||||
|
||||
# Extract only printers INSERTs
|
||||
echo "Extracting printers INSERTs..."
|
||||
grep "^INSERT INTO \`printers\`" "$OUTPUT_DIR/prod_printers.sql" > "$OUTPUT_DIR/prod_printers_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 0;" | cat - "$OUTPUT_DIR/prod_printers_inserts.sql" > temp && mv temp "$OUTPUT_DIR/prod_printers_inserts.sql"
|
||||
echo "SET FOREIGN_KEY_CHECKS = 1;" >> "$OUTPUT_DIR/prod_printers_inserts.sql"
|
||||
|
||||
# Extract only knowledgebase INSERTs
|
||||
echo "Extracting knowledgebase INSERTs..."
|
||||
grep "^INSERT INTO \`knowledgebase\`" "$OUTPUT_DIR/prod_knowledgebase.sql" > "$OUTPUT_DIR/prod_knowledgebase_inserts.sql"
|
||||
echo "ALTER TABLE knowledgebase DISABLE KEYS;" | cat - "$OUTPUT_DIR/prod_knowledgebase_inserts.sql" > temp && mv temp "$OUTPUT_DIR/prod_knowledgebase_inserts.sql"
|
||||
echo "ALTER TABLE knowledgebase ENABLE KEYS;" >> "$OUTPUT_DIR/prod_knowledgebase_inserts.sql"
|
||||
|
||||
echo ""
|
||||
echo "Extraction complete!"
|
||||
echo "Files created:"
|
||||
ls -lh "$OUTPUT_DIR"/*_inserts.sql
|
||||
|
||||
echo ""
|
||||
echo "INSERT statement counts:"
|
||||
echo "Notifications: $(grep -c "^INSERT" "$OUTPUT_DIR/prod_notifications_inserts.sql")"
|
||||
echo "Notification Types: $(grep -c "^INSERT" "$OUTPUT_DIR/prod_notificationtypes_inserts.sql")"
|
||||
echo "Printers: $(grep -c "^INSERT" "$OUTPUT_DIR/prod_printers_inserts.sql")"
|
||||
echo "Knowledgebase: $(grep -c "^INSERT" "$OUTPUT_DIR/prod_knowledgebase_inserts.sql")"
|
||||
@@ -1,153 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: fix_dualpath_controller_relationships.sql
|
||||
-- Purpose: Fix existing relationship issues and propagate controllers to dualpath machines
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
--
|
||||
-- Issues Fixed:
|
||||
-- 1. Incorrect direction: Equipment -> Controls -> PC (should be PC -> Controls -> Equipment)
|
||||
-- 2. Missing controller relationships on dualpath machines
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: FIX INCORRECTLY DIRECTED RELATIONSHIPS
|
||||
-- Equipment should NOT "Control" a PC - flip these to PC -> Controls -> Equipment
|
||||
-- ============================================================================
|
||||
|
||||
-- First, identify the bad relationships (Equipment -> Controls -> PC)
|
||||
SELECT
|
||||
'BAD RELATIONSHIP' AS issue,
|
||||
mr.relationshipid,
|
||||
m1.machinenumber AS equipment_number,
|
||||
m1.hostname AS equipment_hostname,
|
||||
rt.relationshiptype,
|
||||
m2.hostname AS pc_hostname,
|
||||
m2.machinenumber AS pc_machinenumber
|
||||
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 rt.relationshiptype = 'Controls'
|
||||
AND m1.pctypeid IS NULL -- m1 is Equipment (not a PC)
|
||||
AND m2.pctypeid IS NOT NULL -- m2 IS a PC
|
||||
AND mr.isactive = 1;
|
||||
|
||||
-- Fix: Delete the bad relationships and recreate them correctly
|
||||
-- First, save the IDs we need to fix
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS temp_bad_controls AS
|
||||
SELECT
|
||||
mr.relationshipid,
|
||||
mr.machineid AS equipment_machineid,
|
||||
mr.related_machineid AS pc_machineid,
|
||||
mr.relationshiptypeid
|
||||
FROM machinerelationships mr
|
||||
JOIN machines m1 ON mr.machineid = m1.machineid
|
||||
JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
WHERE mr.relationshiptypeid = (SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Controls')
|
||||
AND m1.pctypeid IS NULL
|
||||
AND m2.pctypeid IS NOT NULL
|
||||
AND mr.isactive = 1;
|
||||
|
||||
-- Show what will be fixed
|
||||
SELECT 'Will fix these relationships:' AS status;
|
||||
SELECT * FROM temp_bad_controls;
|
||||
|
||||
-- Delete the bad relationships
|
||||
DELETE mr FROM machinerelationships mr
|
||||
INNER JOIN temp_bad_controls t ON mr.relationshipid = t.relationshipid;
|
||||
|
||||
-- Create the correct relationships (PC -> Controls -> Equipment)
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT
|
||||
pc_machineid AS machineid,
|
||||
equipment_machineid AS related_machineid,
|
||||
relationshiptypeid,
|
||||
1 AS isactive
|
||||
FROM temp_bad_controls t
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships mr2
|
||||
WHERE mr2.machineid = t.pc_machineid
|
||||
AND mr2.related_machineid = t.equipment_machineid
|
||||
AND mr2.relationshiptypeid = t.relationshiptypeid
|
||||
AND mr2.isactive = 1
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_bad_controls;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: PROPAGATE CONTROLLERS TO DUALPATH MACHINES
|
||||
-- If Machine A is controlled by PC, and Machine A has dualpath to Machine B,
|
||||
-- then Machine B should also be controlled by PC
|
||||
-- ============================================================================
|
||||
|
||||
-- Find dualpath machines missing controller relationships
|
||||
SELECT
|
||||
'MISSING CONTROLLER' AS issue,
|
||||
m1.machinenumber AS machine_with_controller,
|
||||
pc.hostname AS controller_pc,
|
||||
m2.machinenumber AS dualpath_machine_missing_controller
|
||||
FROM machinerelationships ctrl
|
||||
JOIN machines m1 ON ctrl.related_machineid = m1.machineid
|
||||
JOIN machines pc ON ctrl.machineid = pc.machineid
|
||||
JOIN machinerelationships dp ON m1.machineid = dp.machineid
|
||||
JOIN machines m2 ON dp.related_machineid = m2.machineid
|
||||
JOIN relationshiptypes rt_ctrl ON ctrl.relationshiptypeid = rt_ctrl.relationshiptypeid
|
||||
JOIN relationshiptypes rt_dp ON dp.relationshiptypeid = rt_dp.relationshiptypeid
|
||||
WHERE rt_ctrl.relationshiptype = 'Controls'
|
||||
AND rt_dp.relationshiptype = 'Dualpath'
|
||||
AND ctrl.isactive = 1
|
||||
AND dp.isactive = 1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships ctrl2
|
||||
WHERE ctrl2.machineid = pc.machineid
|
||||
AND ctrl2.related_machineid = m2.machineid
|
||||
AND ctrl2.relationshiptypeid = ctrl.relationshiptypeid
|
||||
AND ctrl2.isactive = 1
|
||||
);
|
||||
|
||||
-- Create the missing controller relationships
|
||||
INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive)
|
||||
SELECT DISTINCT
|
||||
pc.machineid AS machineid,
|
||||
m2.machineid AS related_machineid,
|
||||
ctrl.relationshiptypeid,
|
||||
1 AS isactive
|
||||
FROM machinerelationships ctrl
|
||||
JOIN machines m1 ON ctrl.related_machineid = m1.machineid
|
||||
JOIN machines pc ON ctrl.machineid = pc.machineid
|
||||
JOIN machinerelationships dp ON m1.machineid = dp.machineid
|
||||
JOIN machines m2 ON dp.related_machineid = m2.machineid
|
||||
JOIN relationshiptypes rt_ctrl ON ctrl.relationshiptypeid = rt_ctrl.relationshiptypeid
|
||||
JOIN relationshiptypes rt_dp ON dp.relationshiptypeid = rt_dp.relationshiptypeid
|
||||
WHERE rt_ctrl.relationshiptype = 'Controls'
|
||||
AND rt_dp.relationshiptype = 'Dualpath'
|
||||
AND ctrl.isactive = 1
|
||||
AND dp.isactive = 1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM machinerelationships ctrl2
|
||||
WHERE ctrl2.machineid = pc.machineid
|
||||
AND ctrl2.related_machineid = m2.machineid
|
||||
AND ctrl2.relationshiptypeid = ctrl.relationshiptypeid
|
||||
AND ctrl2.isactive = 1
|
||||
);
|
||||
|
||||
-- ============================================================================
|
||||
-- VERIFICATION
|
||||
-- ============================================================================
|
||||
|
||||
-- Show all Controls relationships (should be PC -> Equipment)
|
||||
SELECT
|
||||
'CONTROLS RELATIONSHIPS' AS type,
|
||||
pc.hostname AS pc_hostname,
|
||||
pc.machinenumber AS pc_machinenumber,
|
||||
'-> Controls ->' AS direction,
|
||||
equip.machinenumber AS equipment_number,
|
||||
equip.hostname AS equipment_hostname
|
||||
FROM machinerelationships mr
|
||||
JOIN machines pc ON mr.machineid = pc.machineid
|
||||
JOIN machines equip ON mr.related_machineid = equip.machineid
|
||||
JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid
|
||||
WHERE rt.relationshiptype = 'Controls'
|
||||
AND mr.isactive = 1
|
||||
ORDER BY pc.hostname, equip.machinenumber;
|
||||
|
||||
SELECT 'Fix complete!' AS status;
|
||||
@@ -1,139 +0,0 @@
|
||||
-- Fix Printer Names to Follow Convention: CSFNAME-Location-Brand-Description
|
||||
-- Convention: CSF21-7701-HP-Laserjet
|
||||
-- Date: 2025-12-08
|
||||
|
||||
-- =====================================================
|
||||
-- PRINTERS WITH CSF NAMES
|
||||
-- Format: CSF##-Location-Brand-Description
|
||||
-- =====================================================
|
||||
|
||||
-- CSF01 - Materials - Xerox EC8036
|
||||
UPDATE printers SET printerwindowsname = 'CSF01-Materials-Xerox-EC8036' WHERE printerid = 7;
|
||||
|
||||
-- CSF02 - TBD location - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF02-TBD-HP-LaserJet' WHERE printerid = 22;
|
||||
|
||||
-- CSF04 - WJRP2035 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF04-WJRP2035-HP-LaserJet' WHERE printerid = 9;
|
||||
|
||||
-- CSF05 - Spools Inspection - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF05-SpoolsInspection-HP-LaserJet' WHERE printerid = 41;
|
||||
|
||||
-- CSF06 - 3037 - HP LaserJet (already correct format)
|
||||
UPDATE printers SET printerwindowsname = 'CSF06-3037-HP-LaserJet' WHERE printerid = 14;
|
||||
|
||||
-- CSF07 - 3005 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF07-3005-HP-LaserJet' WHERE printerid = 32;
|
||||
|
||||
-- CSF08 - VentureCleanRoom - HP LaserJet (location was missing, using machine assignment)
|
||||
UPDATE printers SET printerwindowsname = 'CSF08-VentureCleanRoom-HP-LaserJet' WHERE printerid = 43;
|
||||
|
||||
-- CSF09 - 2022 - HP LaserJet (already correct format)
|
||||
UPDATE printers SET printerwindowsname = 'CSF09-2022-HP-LaserJet' WHERE printerid = 13;
|
||||
|
||||
-- CSF11 - CMM07 - HP LaserJet (location was missing, using machine assignment)
|
||||
UPDATE printers SET printerwindowsname = 'CSF11-CMM07-HP-LaserJet' WHERE printerid = 10;
|
||||
|
||||
-- CSF12 - 7701 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF12-7701-HP-LaserJet' WHERE printerid = 40;
|
||||
|
||||
-- CSF13 - FPIInspection - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF13-FPIInspection-HP-LaserJet' WHERE printerid = 33;
|
||||
|
||||
-- CSF15 - 6502 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF15-6502-HP-LaserJet' WHERE printerid = 35;
|
||||
|
||||
-- CSF18 - BliskInspection - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF18-BliskInspection-HP-LaserJet' WHERE printerid = 17;
|
||||
|
||||
-- CSF21 - 7701 - HP LaserJet (already correct format)
|
||||
UPDATE printers SET printerwindowsname = 'CSF21-7701-HP-LaserJet' WHERE printerid = 39;
|
||||
|
||||
-- CSF22 - WJRP2335 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'CSF22-WJRP2335-HP-LaserJet' WHERE printerid = 20;
|
||||
|
||||
-- =====================================================
|
||||
-- PRINTERS WITHOUT CSF NAMES
|
||||
-- Format: Location-Brand-Description
|
||||
-- =====================================================
|
||||
|
||||
-- 1364 - Xerox Versalink
|
||||
UPDATE printers SET printerwindowsname = '1364-Xerox-Versalink' WHERE printerid = 34;
|
||||
|
||||
-- 6502 - HP LaserJet (Color)
|
||||
UPDATE printers SET printerwindowsname = '6502-HP-ColorLaserJet' WHERE printerid = 49;
|
||||
|
||||
-- 6503 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = '6503-HP-LaserJet' WHERE printerid = 50;
|
||||
|
||||
-- Blisk Inspection - Xerox Versalink
|
||||
UPDATE printers SET printerwindowsname = 'BliskInspection-Xerox-Versalink' WHERE printerid = 18;
|
||||
|
||||
-- Coaching 112 - HP ColorLaserJet
|
||||
UPDATE printers SET printerwindowsname = 'Coaching112-HP-ColorLaserJet' WHERE printerid = 6;
|
||||
|
||||
-- Coaching 115 - Xerox Versalink (THE PROBLEM PRINTER!)
|
||||
UPDATE printers SET printerwindowsname = 'Coaching115-Xerox-Versalink' WHERE printerid = 4;
|
||||
|
||||
-- Guard Desk - HID DTC4500 (card printer)
|
||||
UPDATE printers SET printerwindowsname = 'GuardDesk-HID-DTC4500' WHERE printerid = 46;
|
||||
|
||||
-- Lean Office - HP DesignJet (plotter)
|
||||
UPDATE printers SET printerwindowsname = 'LeanOffice-HP-DesignJet' WHERE printerid = 36;
|
||||
|
||||
-- Office Administration - Xerox Versalink
|
||||
UPDATE printers SET printerwindowsname = 'OfficeAdmin-Xerox-Versalink' WHERE printerid = 23;
|
||||
|
||||
-- PE Room - Xerox Altalink
|
||||
UPDATE printers SET printerwindowsname = 'PERoom-Xerox-Altalink' WHERE printerid = 8;
|
||||
|
||||
-- Router Room - Xerox Versalink
|
||||
UPDATE printers SET printerwindowsname = 'RouterRoom-Xerox-Versalink' WHERE printerid = 11;
|
||||
|
||||
-- Shipping Office - Xerox EC8036
|
||||
UPDATE printers SET printerwindowsname = 'ShippingOffice-Xerox-EC8036' WHERE printerid = 16;
|
||||
|
||||
-- Southern Office - Xerox EC8036
|
||||
UPDATE printers SET printerwindowsname = 'SouthernOffice-Xerox-EC8036' WHERE printerid = 24;
|
||||
|
||||
-- Southern Office - Xerox Versalink (different printer, B7125)
|
||||
UPDATE printers SET printerwindowsname = 'SouthernOffice-Xerox-VersalinkBW' WHERE printerid = 3;
|
||||
|
||||
-- Spools Inspection - Xerox Versalink C405
|
||||
UPDATE printers SET printerwindowsname = 'SpoolsInspection-Xerox-Versalink' WHERE printerid = 37;
|
||||
|
||||
-- Spools Inspection - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'SpoolsInspection-HP-LaserJet' WHERE printerid = 48;
|
||||
|
||||
-- Venture Inspection - Xerox Versalink
|
||||
UPDATE printers SET printerwindowsname = 'VentureInspection-Xerox-Versalink' WHERE printerid = 38;
|
||||
|
||||
-- =====================================================
|
||||
-- SPECIAL CASES / NEED REVIEW
|
||||
-- =====================================================
|
||||
|
||||
-- Gage Lab - HP LaserJet (has "gage lab " as CSF name with trailing space)
|
||||
UPDATE printers SET printerwindowsname = 'GageLab-SpoolsInspection-HP-LaserJet', printercsfname = 'GageLab' WHERE printerid = 44;
|
||||
|
||||
-- HP4001_SPOOLSHWACHEON - Machine 2004 - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'SpoolsHwacheon-2004-HP-LaserJet', printercsfname = '' WHERE printerid = 42;
|
||||
|
||||
-- HP4250_IMPACT - Shipping Office - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'ShippingOffice-HP-LaserJet', printercsfname = '' WHERE printerid = 12;
|
||||
|
||||
-- TBD Was 08 - IT Closet - HP LaserJet (needs real CSF name)
|
||||
UPDATE printers SET printerwindowsname = 'ITCloset-HP-LaserJet', printercsfname = '' WHERE printerid = 45;
|
||||
|
||||
-- 7901 - HP ColorLaserJet (USB printer)
|
||||
UPDATE printers SET printerwindowsname = '7901-HP-ColorLaserJet' WHERE printerid = 30;
|
||||
|
||||
-- Guard Desk USB - HP LaserJet
|
||||
UPDATE printers SET printerwindowsname = 'GuardDesk-HP-LaserJet-USB' WHERE printerid = 28;
|
||||
|
||||
-- NULL location USB printer
|
||||
UPDATE printers SET printerwindowsname = 'USB-HP-ColorLaserJet' WHERE printerid = 31;
|
||||
|
||||
-- =====================================================
|
||||
-- Verification query - run after updates
|
||||
-- =====================================================
|
||||
-- SELECT printerid, printerwindowsname, printercsfname FROM printers WHERE isactive = 1 ORDER BY printerwindowsname;
|
||||
@@ -1,20 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Fix Views for Production
|
||||
--
|
||||
-- This script has been superseded by view_consolidation.sql
|
||||
--
|
||||
-- Run view_consolidation.sql instead, which:
|
||||
-- 1. Drops 27 unused views
|
||||
-- 2. Keeps 2 actually used views (vw_network_devices, vw_warranty_status)
|
||||
-- 3. Creates 11 new purpose-built views for UI pages
|
||||
--
|
||||
-- Also run these scripts for other pending migrations:
|
||||
-- - migration_drop_network_device_tables.sql (migrates servers, drops legacy tables)
|
||||
-- - migration_drop_legacy_tables.sql (drops machineoverrides, dualpathassignments, etc.)
|
||||
--
|
||||
-- LocationOnly machine fix (run manually):
|
||||
-- UPDATE machines SET modelnumberid = 1 WHERE islocationonly = 1;
|
||||
-- ============================================================================
|
||||
|
||||
-- Just run view_consolidation.sql
|
||||
SELECT 'Please run view_consolidation.sql instead of this script' AS message;
|
||||
@@ -1,151 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Clean import of production data using only INSERT statements
|
||||
# This avoids schema conflicts
|
||||
|
||||
echo "=========================================="
|
||||
echo "Production Data Import (Clean)"
|
||||
echo "Date: 2025-11-13"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
MYSQL_CMD="docker exec -i dev-mysql mysql -u root -prootpassword shopdb"
|
||||
|
||||
echo "Step 1: Creating backup tables..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
DROP TABLE IF EXISTS `notifications_backup_20251113`;
|
||||
CREATE TABLE `notifications_backup_20251113` LIKE `notifications`;
|
||||
INSERT INTO `notifications_backup_20251113` SELECT * FROM `notifications`;
|
||||
|
||||
DROP TABLE IF EXISTS `notificationtypes_backup_20251113`;
|
||||
CREATE TABLE `notificationtypes_backup_20251113` LIKE `notificationtypes`;
|
||||
INSERT INTO `notificationtypes_backup_20251113` SELECT * FROM `notificationtypes`;
|
||||
|
||||
DROP TABLE IF EXISTS `printers_backup_20251113`;
|
||||
CREATE TABLE `printers_backup_20251113` LIKE `printers`;
|
||||
INSERT INTO `printers_backup_20251113` SELECT * FROM `printers`;
|
||||
|
||||
DROP TABLE IF EXISTS `knowledgebase_backup_20251113`;
|
||||
CREATE TABLE `knowledgebase_backup_20251113` LIKE `knowledgebase`;
|
||||
INSERT INTO `knowledgebase_backup_20251113` SELECT * FROM `knowledgebase`;
|
||||
|
||||
SELECT 'Backup tables created' AS status;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Showing current counts..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== BEFORE IMPORT ===' AS '';
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM notifications) AS notifications_before,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS notificationtypes_before,
|
||||
(SELECT COUNT(*) FROM printers) AS printers_before,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS knowledgebase_before;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 3: Clearing existing data and importing notification types..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
DELETE FROM notifications;
|
||||
DELETE FROM notificationtypes;
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
EOF
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notificationtypes_inserts.sql | $MYSQL_CMD 2>&1 | grep -E "status|ERROR" || echo " ✓ Notification types imported"
|
||||
|
||||
echo ""
|
||||
echo "Step 4: Importing notifications..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notifications_inserts.sql | $MYSQL_CMD 2>&1 | grep -E "status|ERROR" || echo " ✓ Notifications imported"
|
||||
|
||||
echo ""
|
||||
echo "Step 5: Importing printers..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
DELETE FROM printers;
|
||||
EOF
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_printers_inserts.sql | $MYSQL_CMD 2>&1 | grep -E "status|ERROR" || echo " ✓ Printers imported"
|
||||
|
||||
echo ""
|
||||
echo "Step 6: Importing knowledgebase..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
DELETE FROM knowledgebase;
|
||||
EOF
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_knowledgebase_inserts.sql | $MYSQL_CMD 2>&1 | grep -E "status|ERROR" || echo " ✓ Knowledgebase imported"
|
||||
|
||||
echo ""
|
||||
echo "Step 7: Verifying imported data..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== AFTER IMPORT ===' AS '';
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM notifications) AS notifications_after,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS notificationtypes_after,
|
||||
(SELECT COUNT(*) FROM printers) AS printers_after,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS knowledgebase_after;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 8: Data Comparison..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== Import Summary ===' AS '';
|
||||
SELECT
|
||||
'Notifications' AS table_name,
|
||||
(SELECT COUNT(*) FROM notifications_backup_20251113) AS before_count,
|
||||
(SELECT COUNT(*) FROM notifications) AS after_count,
|
||||
(SELECT COUNT(*) FROM notifications) - (SELECT COUNT(*) FROM notifications_backup_20251113) AS difference;
|
||||
|
||||
SELECT
|
||||
'Notification Types' AS table_name,
|
||||
(SELECT COUNT(*) FROM notificationtypes_backup_20251113) AS before_count,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS after_count,
|
||||
(SELECT COUNT(*) FROM notificationtypes) - (SELECT COUNT(*) FROM notificationtypes_backup_20251113) AS difference;
|
||||
|
||||
SELECT
|
||||
'Printers' AS table_name,
|
||||
(SELECT COUNT(*) FROM printers_backup_20251113) AS before_count,
|
||||
(SELECT COUNT(*) FROM printers) AS after_count,
|
||||
(SELECT COUNT(*) FROM printers) - (SELECT COUNT(*) FROM printers_backup_20251113) AS difference;
|
||||
|
||||
SELECT
|
||||
'Knowledgebase' AS table_name,
|
||||
(SELECT COUNT(*) FROM knowledgebase_backup_20251113) AS before_count,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS after_count,
|
||||
(SELECT COUNT(*) FROM knowledgebase) - (SELECT COUNT(*) FROM knowledgebase_backup_20251113) AS difference;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 9: Sample data verification..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== Notification Types ===' AS '';
|
||||
SELECT notificationtypeid, typename, typedescription, typecolor
|
||||
FROM notificationtypes
|
||||
ORDER BY notificationtypeid;
|
||||
|
||||
SELECT '=== Recent Active Notifications (Top 5) ===' AS '';
|
||||
SELECT notificationid, notificationtypeid, notification, DATE_FORMAT(starttime, '%Y-%m-%d %H:%i') AS start, isactive
|
||||
FROM notifications
|
||||
WHERE isactive = 1
|
||||
ORDER BY starttime DESC
|
||||
LIMIT 5;
|
||||
|
||||
SELECT '=== Active Printers (Top 10) ===' AS '';
|
||||
SELECT printerid, printerwindowsname, ipaddress, isactive
|
||||
FROM printers
|
||||
WHERE isactive = 1
|
||||
LIMIT 10;
|
||||
|
||||
SELECT '=== Top Knowledge Base Articles ===' AS '';
|
||||
SELECT linkid, LEFT(shortdescription, 70) AS description, clicks
|
||||
FROM knowledgebase
|
||||
WHERE isactive = 1
|
||||
ORDER BY clicks DESC
|
||||
LIMIT 10;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "✓ IMPORT COMPLETE!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Backup tables saved with _backup_20251113 suffix"
|
||||
echo ""
|
||||
echo "To rollback, run:"
|
||||
echo " bash /home/camp/projects/windows/shopdb/sql/rollback_prod_import.sh"
|
||||
echo ""
|
||||
@@ -1,110 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Direct import of production data into dev database
|
||||
# This script concatenates all SQL files and imports them in one go
|
||||
|
||||
echo "=========================================="
|
||||
echo "Production Data Import Script"
|
||||
echo "Date: 2025-11-13"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
MYSQL_CMD="docker exec -i dev-mysql mysql -u root -prootpassword shopdb"
|
||||
|
||||
echo "Step 1: Creating backup tables..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
DROP TABLE IF EXISTS `notifications_backup_20251113`;
|
||||
CREATE TABLE `notifications_backup_20251113` LIKE `notifications`;
|
||||
INSERT INTO `notifications_backup_20251113` SELECT * FROM `notifications`;
|
||||
|
||||
DROP TABLE IF EXISTS `notificationtypes_backup_20251113`;
|
||||
CREATE TABLE `notificationtypes_backup_20251113` LIKE `notificationtypes`;
|
||||
INSERT INTO `notificationtypes_backup_20251113` SELECT * FROM `notificationtypes`;
|
||||
|
||||
DROP TABLE IF EXISTS `printers_backup_20251113`;
|
||||
CREATE TABLE `printers_backup_20251113` LIKE `printers`;
|
||||
INSERT INTO `printers_backup_20251113` SELECT * FROM `printers`;
|
||||
|
||||
DROP TABLE IF EXISTS `knowledgebase_backup_20251113`;
|
||||
CREATE TABLE `knowledgebase_backup_20251113` LIKE `knowledgebase`;
|
||||
INSERT INTO `knowledgebase_backup_20251113` SELECT * FROM `knowledgebase`;
|
||||
|
||||
SELECT 'Backup tables created' AS status;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Showing current counts..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== BEFORE IMPORT ===' AS '';
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM notifications) AS notifications_before,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS notificationtypes_before,
|
||||
(SELECT COUNT(*) FROM printers) AS printers_before,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS knowledgebase_before;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 3: Importing notification types..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notificationtypes.sql | $MYSQL_CMD 2>&1 | tail -5
|
||||
|
||||
echo ""
|
||||
echo "Step 4: Importing notifications..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notifications.sql | $MYSQL_CMD 2>&1 | tail -5
|
||||
|
||||
echo ""
|
||||
echo "Step 5: Importing printers..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_printers.sql | $MYSQL_CMD 2>&1 | tail -5
|
||||
|
||||
echo ""
|
||||
echo "Step 6: Importing knowledgebase..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_knowledgebase.sql | $MYSQL_CMD 2>&1 | tail -5
|
||||
|
||||
echo ""
|
||||
echo "Step 7: Verifying imported data..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== AFTER IMPORT ===' AS '';
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM notifications) AS notifications_after,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS notificationtypes_after,
|
||||
(SELECT COUNT(*) FROM printers) AS printers_after,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS knowledgebase_after;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Step 8: Sample data verification..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== Notification Types ===' AS '';
|
||||
SELECT notificationtypeid, typename, typedescription, typecolor, isactive
|
||||
FROM notificationtypes
|
||||
ORDER BY notificationtypeid;
|
||||
|
||||
SELECT '=== Recent Active Notifications (Top 5) ===' AS '';
|
||||
SELECT notificationid, notificationtypeid, notification, starttime, endtime, ticketnumber, isactive
|
||||
FROM notifications
|
||||
WHERE isactive = 1
|
||||
ORDER BY starttime DESC
|
||||
LIMIT 5;
|
||||
|
||||
SELECT '=== Active Printers (Top 10) ===' AS '';
|
||||
SELECT printerid, printerwindowsname, ipaddress, serialnumber, isactive, iscsf
|
||||
FROM printers
|
||||
WHERE isactive = 1
|
||||
LIMIT 10;
|
||||
|
||||
SELECT '=== Top Knowledge Base Articles (Top 10) ===' AS '';
|
||||
SELECT linkid, LEFT(shortdescription, 60) AS description, clicks, isactive
|
||||
FROM knowledgebase
|
||||
WHERE isactive = 1
|
||||
ORDER BY clicks DESC
|
||||
LIMIT 10;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "IMPORT COMPLETE!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Backup tables created with _backup_20251113 suffix"
|
||||
echo ""
|
||||
echo "To rollback, run:"
|
||||
echo " bash /home/camp/projects/windows/shopdb/sql/rollback_prod_import.sh"
|
||||
echo ""
|
||||
@@ -1,64 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Final Production Data Import - Uses the original extracted files
|
||||
# Directly pipes the SQL with proper DELETE statements
|
||||
|
||||
echo "=========================================="
|
||||
echo "Production Data Import - Final"
|
||||
echo "Date: 2025-11-13"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
MYSQL_CMD="docker exec -i dev-mysql mysql -u root -prootpassword shopdb"
|
||||
|
||||
echo "Creating backups..."
|
||||
$MYSQL_CMD <<'EOF'
|
||||
DROP TABLE IF EXISTS notifications_backup_20251113;
|
||||
DROP TABLE IF EXISTS notificationtypes_backup_20251113;
|
||||
DROP TABLE IF EXISTS printers_backup_20251113;
|
||||
DROP TABLE IF EXISTS knowledgebase_backup_20251113;
|
||||
|
||||
CREATE TABLE notifications_backup_20251113 LIKE notifications;
|
||||
INSERT INTO notifications_backup_20251113 SELECT * FROM notifications;
|
||||
|
||||
CREATE TABLE notificationtypes_backup_20251113 LIKE notificationtypes;
|
||||
INSERT INTO notificationtypes_backup_20251113 SELECT * FROM notificationtypes;
|
||||
|
||||
CREATE TABLE printers_backup_20251113 LIKE printers;
|
||||
INSERT INTO printers_backup_20251113 SELECT * FROM printers;
|
||||
|
||||
CREATE TABLE knowledgebase_backup_20251113 LIKE knowledgebase;
|
||||
INSERT INTO knowledgebase_backup_20251113 SELECT * FROM knowledgebase;
|
||||
EOF
|
||||
|
||||
echo "✓ Backups created"
|
||||
echo ""
|
||||
|
||||
echo "Importing production data..."
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notificationtypes.sql | $MYSQL_CMD 2>&1 | tail -1
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_notifications.sql | $MYSQL_CMD 2>&1 | tail -1
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_printers.sql | $MYSQL_CMD 2>&1 | tail -1
|
||||
cat /home/camp/projects/windows/shopdb/sql/prod_knowledgebase.sql | $MYSQL_CMD 2>&1 | tail -1
|
||||
|
||||
echo ""
|
||||
echo "✓ Import complete"
|
||||
echo ""
|
||||
|
||||
$MYSQL_CMD <<'EOF'
|
||||
SELECT '=== IMPORT RESULTS ===' AS '';
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM notifications) AS notifications,
|
||||
(SELECT COUNT(*) FROM notificationtypes) AS notificationtypes,
|
||||
(SELECT COUNT(*) FROM printers) AS printers,
|
||||
(SELECT COUNT(*) FROM knowledgebase) AS knowledgebase;
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "✓ Production data imported successfully!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "NOTE: All notifications have notificationtypeid=1 (gray)"
|
||||
echo "Use bulk_update_notification_types.asp to assign colors"
|
||||
echo ""
|
||||
echo "Access at: http://192.168.122.151:8080/bulk_update_notification_types.asp"
|
||||
echo ""
|
||||
@@ -1,55 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- Migration: Move Printer IP Addresses from machines to communications Table
|
||||
-- Date: 2025-11-14
|
||||
-- Purpose: Migrate printer IP data to communications table before removing
|
||||
-- ipaddress1/2/3 columns from machines table
|
||||
-- =============================================================================
|
||||
|
||||
-- STEP 1: Migrate printer IP addresses to communications table
|
||||
-- Note: Printers use comstypeid = 1 (Network) for IP addresses
|
||||
-- Use isprimary = 1 to indicate this is the primary network interface
|
||||
|
||||
INSERT INTO communications (machineid, comstypeid, address, isprimary, isactive, lastupdated)
|
||||
SELECT
|
||||
m.machineid,
|
||||
1 AS comstypeid, -- Network communication type
|
||||
m.ipaddress1 AS address,
|
||||
1 AS isprimary, -- Primary network interface
|
||||
1 AS isactive,
|
||||
NOW() AS lastupdated
|
||||
FROM machines m
|
||||
WHERE m.machinetypeid = 15 -- Printers
|
||||
AND m.ipaddress1 IS NOT NULL
|
||||
AND m.ipaddress1 != ''
|
||||
AND NOT EXISTS (
|
||||
-- Don't insert if this printer already has a communications record
|
||||
SELECT 1 FROM communications c
|
||||
WHERE c.machineid = m.machineid
|
||||
AND c.comstypeid = 1
|
||||
);
|
||||
|
||||
-- =============================================================================
|
||||
-- Verification Queries
|
||||
-- =============================================================================
|
||||
|
||||
-- Check how many printer IPs were migrated
|
||||
-- SELECT COUNT(*) as migrated_printer_ips
|
||||
-- FROM communications c
|
||||
-- INNER JOIN machines m ON c.machineid = m.machineid
|
||||
-- WHERE m.machinetypeid = 15 AND c.comstypeid = 1;
|
||||
|
||||
-- Compare machines.ipaddress1 vs communications.address for printers
|
||||
-- SELECT
|
||||
-- m.machineid,
|
||||
-- m.alias,
|
||||
-- m.ipaddress1 as old_ip,
|
||||
-- c.address as new_ip
|
||||
-- FROM machines m
|
||||
-- LEFT JOIN communications c ON m.machineid = c.machineid AND c.comstypeid = 1
|
||||
-- WHERE m.machinetypeid = 15
|
||||
-- ORDER BY m.machineid;
|
||||
|
||||
-- =============================================================================
|
||||
-- Status: Ready to execute
|
||||
-- Impact: Migrates 32 printer IP addresses to communications table
|
||||
-- =============================================================================
|
||||
@@ -1,81 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Migration: Drop Legacy Tables
|
||||
--
|
||||
-- This script removes unused legacy tables after data migration to unified
|
||||
-- tables (machinerelationships, communications).
|
||||
--
|
||||
-- Tables to drop:
|
||||
-- - machineoverrides (empty, functionality not used)
|
||||
-- - dualpathassignments (migrated to machinerelationships)
|
||||
-- - networkinterfaces (migrated to communications)
|
||||
-- - _backup_equipment_ips_phase1_5 (old migration backup)
|
||||
--
|
||||
-- IMPORTANT: Run this on DEV first and test thoroughly before production!
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: Drop views that reference legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
DROP VIEW IF EXISTS vw_shopfloor_pcs;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: Drop FK constraints on legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE dualpathassignments DROP FOREIGN KEY fk_dualpathassignments_machines;
|
||||
ALTER TABLE machineoverrides DROP FOREIGN KEY fk_machineoverrides_machines;
|
||||
ALTER TABLE networkinterfaces DROP FOREIGN KEY fk_networkinterfaces_machines;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 3: Drop the legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS machineoverrides;
|
||||
DROP TABLE IF EXISTS dualpathassignments;
|
||||
DROP TABLE IF EXISTS networkinterfaces;
|
||||
DROP TABLE IF EXISTS _backup_equipment_ips_phase1_5;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 4: Recreate vw_shopfloor_pcs without machineoverrides reference
|
||||
-- ============================================================================
|
||||
|
||||
CREATE VIEW vw_shopfloor_pcs AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
m.machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
m.lastupdated,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY m.machinenumber, m.hostname;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 5: Verify
|
||||
-- ============================================================================
|
||||
|
||||
-- Should NOT show dropped tables
|
||||
SELECT 'Verifying tables are dropped:' AS status;
|
||||
SHOW TABLES LIKE 'machineoverrides';
|
||||
SHOW TABLES LIKE 'dualpathassignments';
|
||||
SHOW TABLES LIKE 'networkinterfaces';
|
||||
SHOW TABLES LIKE '_backup%';
|
||||
|
||||
-- Verify view works
|
||||
SELECT 'Testing vw_shopfloor_pcs:' AS status;
|
||||
SELECT COUNT(*) AS shopfloor_pc_count FROM vw_shopfloor_pcs;
|
||||
|
||||
SELECT 'Migration complete! Legacy tables have been dropped.' AS status;
|
||||
@@ -1,161 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Migration: Drop Legacy Network Device Tables
|
||||
--
|
||||
-- This script removes the old network device tables (accesspoints, cameras,
|
||||
-- idfs, servers, switches) after migrating all data and dependencies to use
|
||||
-- the unified machines table.
|
||||
--
|
||||
-- IMPORTANT: Run this on DEV first and test thoroughly before production!
|
||||
--
|
||||
-- Prerequisites:
|
||||
-- - All network devices should already be in machines table with appropriate
|
||||
-- machinetypeid values (16=Access Point, 17=Camera, 18=IDF, 19=Switch, 20=Server)
|
||||
-- - displaydevice.asp and displaylocationdevice.asp should be updated to
|
||||
-- use machines table instead of legacy tables
|
||||
-- - networkdevices.asp already uses vw_network_devices (no changes needed)
|
||||
-- - deviceserver.asp already uses machines table (no changes needed)
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: Migrate any remaining data from legacy servers table to machines
|
||||
-- ============================================================================
|
||||
|
||||
-- The 3 servers in the legacy table need to be migrated to machines table
|
||||
-- Check if they already exist (by hostname/alias or IP)
|
||||
-- If not, insert them
|
||||
|
||||
-- First, check what we're working with
|
||||
SELECT 'Servers to migrate:' AS status;
|
||||
SELECT serverid, servername, ipaddress, description, fqdn FROM servers;
|
||||
|
||||
-- Insert servers that don't already exist in machines (matching by FQDN or name)
|
||||
INSERT INTO machines (alias, machinetypeid, serialnumber, fqdn, machinenotes, isactive, maptop, mapleft, lastupdated)
|
||||
SELECT
|
||||
TRIM(s.servername) AS alias,
|
||||
20 AS machinetypeid, -- Server
|
||||
s.serialnumber,
|
||||
s.fqdn,
|
||||
s.description AS machinenotes,
|
||||
CASE WHEN s.isactive = '' OR s.isactive IS NULL THEN 1 ELSE 1 END AS isactive,
|
||||
NULL AS maptop,
|
||||
NULL AS mapleft,
|
||||
NOW() AS lastupdated
|
||||
FROM servers s
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM machines m
|
||||
WHERE m.machinetypeid = 20
|
||||
AND (
|
||||
(m.fqdn IS NOT NULL AND m.fqdn = s.fqdn)
|
||||
OR (m.alias IS NOT NULL AND m.alias = TRIM(s.servername))
|
||||
)
|
||||
);
|
||||
|
||||
-- Add IP addresses to communications table for migrated servers
|
||||
INSERT INTO communications (machineid, comstypeid, address, isprimary, isactive)
|
||||
SELECT
|
||||
m.machineid,
|
||||
1 AS comstypeid, -- IP type
|
||||
TRIM(s.ipaddress) AS address,
|
||||
1 AS isprimary,
|
||||
1 AS isactive
|
||||
FROM servers s
|
||||
JOIN machines m ON (
|
||||
m.machinetypeid = 20
|
||||
AND (
|
||||
(m.fqdn IS NOT NULL AND m.fqdn = s.fqdn)
|
||||
OR (m.alias IS NOT NULL AND m.alias = TRIM(s.servername))
|
||||
)
|
||||
)
|
||||
WHERE s.ipaddress IS NOT NULL
|
||||
AND TRIM(s.ipaddress) <> ''
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM communications c
|
||||
WHERE c.machineid = m.machineid
|
||||
AND c.address = TRIM(s.ipaddress)
|
||||
);
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: Drop Foreign Key Constraints
|
||||
-- ============================================================================
|
||||
|
||||
-- cameras.idfid references idfs.idfid
|
||||
ALTER TABLE cameras DROP FOREIGN KEY cameras_ibfk_1;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 3: Drop Views that depend on legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
DROP VIEW IF EXISTS vw_idf_inventory;
|
||||
DROP VIEW IF EXISTS vw_infrastructure_summary;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 4: Drop the legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS cameras;
|
||||
DROP TABLE IF EXISTS switches;
|
||||
DROP TABLE IF EXISTS accesspoints;
|
||||
DROP TABLE IF EXISTS servers;
|
||||
DROP TABLE IF EXISTS idfs;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 5: Recreate views using machines table
|
||||
-- ============================================================================
|
||||
|
||||
-- vw_idf_inventory: IDF locations with camera counts
|
||||
-- IDFs are machinetypeid = 17, Cameras are machinetypeid = 18
|
||||
CREATE VIEW vw_idf_inventory AS
|
||||
SELECT
|
||||
m.machineid AS idfid,
|
||||
COALESCE(m.alias, m.machinenumber) AS idfname,
|
||||
m.machinenotes AS description,
|
||||
m.maptop,
|
||||
m.mapleft,
|
||||
(SELECT COUNT(DISTINCT cam.machineid)
|
||||
FROM machines cam
|
||||
JOIN machinerelationships mr ON cam.machineid = mr.machineid
|
||||
WHERE mr.related_machineid = m.machineid
|
||||
AND cam.machinetypeid = 18
|
||||
AND cam.isactive = 1) AS camera_count,
|
||||
m.isactive
|
||||
FROM machines m
|
||||
WHERE m.machinetypeid = 17 -- IDF
|
||||
AND m.isactive = 1;
|
||||
|
||||
-- vw_infrastructure_summary: Counts of network device types
|
||||
CREATE VIEW vw_infrastructure_summary AS
|
||||
SELECT
|
||||
mt.machinetype AS device_type,
|
||||
COUNT(*) AS total_count,
|
||||
SUM(CASE WHEN m.isactive = 1 THEN 1 ELSE 0 END) AS active_count
|
||||
FROM machines m
|
||||
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
|
||||
WHERE m.machinetypeid IN (16, 17, 18, 19, 20) -- Network device types
|
||||
GROUP BY mt.machinetypeid, mt.machinetype
|
||||
ORDER BY mt.machinetype;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 6: Verify
|
||||
-- ============================================================================
|
||||
|
||||
-- Should NOT show legacy tables anymore
|
||||
SELECT 'Tables remaining with legacy names:' AS status;
|
||||
SHOW TABLES LIKE 'accesspoints';
|
||||
SHOW TABLES LIKE 'cameras';
|
||||
SHOW TABLES LIKE 'idfs';
|
||||
SHOW TABLES LIKE 'servers';
|
||||
SHOW TABLES LIKE 'switches';
|
||||
|
||||
-- Verify network devices are accessible via machines table
|
||||
SELECT 'Network devices in machines table:' AS status;
|
||||
SELECT mt.machinetype, COUNT(*) as cnt
|
||||
FROM machines m
|
||||
JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
|
||||
WHERE m.machinetypeid IN (16, 17, 18, 19, 20)
|
||||
GROUP BY mt.machinetypeid, mt.machinetype;
|
||||
|
||||
-- Verify views work
|
||||
SELECT 'Testing vw_infrastructure_summary:' AS status;
|
||||
SELECT * FROM vw_infrastructure_summary;
|
||||
|
||||
SELECT 'Migration complete! Legacy network device tables have been dropped.' AS status;
|
||||
@@ -1,287 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Migration: Drop Legacy PC Tables
|
||||
--
|
||||
-- This script removes the old pc table and pc_to_machine_id_mapping after
|
||||
-- migrating all dependencies to use machines.machineid directly.
|
||||
--
|
||||
-- IMPORTANT: Run this on DEV first and test thoroughly before production!
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: Drop Foreign Key Constraints referencing pc table
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE commconfig DROP FOREIGN KEY commconfig_ibfk_1;
|
||||
ALTER TABLE dncconfig DROP FOREIGN KEY dncconfig_ibfk_1;
|
||||
ALTER TABLE dualpathassignments DROP FOREIGN KEY dualpathassignments_ibfk_1;
|
||||
ALTER TABLE machineoverrides DROP FOREIGN KEY machineoverrides_ibfk_1;
|
||||
ALTER TABLE networkinterfaces DROP FOREIGN KEY networkinterfaces_ibfk_1;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: Drop Views that depend on pc_to_machine_id_mapping
|
||||
-- ============================================================================
|
||||
|
||||
DROP VIEW IF EXISTS vw_active_pcs;
|
||||
DROP VIEW IF EXISTS vw_dnc_config;
|
||||
DROP VIEW IF EXISTS vw_engineer_pcs;
|
||||
DROP VIEW IF EXISTS vw_pc_network_summary;
|
||||
DROP VIEW IF EXISTS vw_pc_resolved_machines;
|
||||
DROP VIEW IF EXISTS vw_pcs_by_hardware;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_comm_config;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_pcs;
|
||||
DROP VIEW IF EXISTS vw_standard_pcs;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 3: Update tables - rename pcid columns to machineid
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE machineoverrides CHANGE COLUMN pcid machineid INT(11);
|
||||
ALTER TABLE dualpathassignments CHANGE COLUMN pcid machineid INT(11);
|
||||
ALTER TABLE networkinterfaces CHANGE COLUMN pcid machineid INT(11);
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 4: Clean up orphaned records (referencing non-existent machineids)
|
||||
-- ============================================================================
|
||||
|
||||
DELETE FROM dualpathassignments WHERE machineid NOT IN (SELECT machineid FROM machines);
|
||||
DELETE FROM networkinterfaces WHERE machineid NOT IN (SELECT machineid FROM machines);
|
||||
DELETE FROM commconfig WHERE machineid NOT IN (SELECT machineid FROM machines);
|
||||
DELETE FROM dncconfig WHERE machineid NOT IN (SELECT machineid FROM machines);
|
||||
DELETE FROM machineoverrides WHERE machineid NOT IN (SELECT machineid FROM machines);
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 5: Add new FK constraints pointing to machines table
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE machineoverrides ADD CONSTRAINT fk_machineoverrides_machines
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid);
|
||||
ALTER TABLE dualpathassignments ADD CONSTRAINT fk_dualpathassignments_machines
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid);
|
||||
ALTER TABLE networkinterfaces ADD CONSTRAINT fk_networkinterfaces_machines
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid);
|
||||
ALTER TABLE commconfig ADD CONSTRAINT fk_commconfig_machines
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid);
|
||||
ALTER TABLE dncconfig ADD CONSTRAINT fk_dncconfig_machines
|
||||
FOREIGN KEY (machineid) REFERENCES machines(machineid);
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 6: Drop the legacy tables
|
||||
-- ============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS pc_backup_phase2;
|
||||
DROP TABLE IF EXISTS pc;
|
||||
DROP TABLE IF EXISTS pc_to_machine_id_mapping;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 7: Recreate Views using machines.machineid instead of pcid
|
||||
-- ============================================================================
|
||||
|
||||
-- vw_active_pcs: All active PCs (updated in last 30 days)
|
||||
CREATE VIEW vw_active_pcs AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
COALESCE(v.vendor, 'Unknown') AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
m.machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
COALESCE(pt.typename, 'Unknown') AS pctype,
|
||||
COALESCE(pt.description, 'Unknown') AS typedescription,
|
||||
CASE
|
||||
WHEN w.enddate IS NULL THEN 'Unknown'
|
||||
WHEN w.enddate < CURDATE() THEN 'Expired'
|
||||
WHEN w.enddate < DATE_ADD(CURDATE(), INTERVAL 90 DAY) THEN 'Expiring Soon'
|
||||
ELSE 'Active'
|
||||
END AS warrantystatus,
|
||||
w.enddate AS warrantyenddate,
|
||||
CASE
|
||||
WHEN w.enddate IS NULL THEN NULL
|
||||
ELSE DATEDIFF(w.enddate, CURDATE())
|
||||
END AS warrantydaysremaining,
|
||||
m.lastupdated,
|
||||
DATEDIFF(NOW(), m.lastupdated) AS daysold,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
LEFT JOIN warranties w ON m.machineid = w.machineid
|
||||
WHERE m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL;
|
||||
|
||||
-- vw_dnc_config: PCs with DNC/communication config
|
||||
CREATE VIEW vw_dnc_config AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.machinenumber,
|
||||
c.address AS ip_address,
|
||||
c.port AS socket,
|
||||
c.settings AS config_settings,
|
||||
ct.typename AS comm_type
|
||||
FROM machines m
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isactive = 1
|
||||
LEFT JOIN comstypes ct ON c.comstypeid = ct.comstypeid
|
||||
WHERE m.pctypeid IS NOT NULL
|
||||
AND ct.typename IN ('IP', 'Serial')
|
||||
ORDER BY m.hostname, ct.typename;
|
||||
|
||||
-- vw_engineer_pcs: Engineer-type PCs
|
||||
CREATE VIEW vw_engineer_pcs AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
m.machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
m.lastupdated
|
||||
FROM machines m
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Engineer'
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- vw_pc_network_summary: Network interface summary per PC
|
||||
CREATE VIEW vw_pc_network_summary AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.machinenumber,
|
||||
COUNT(c.comid) AS interface_count,
|
||||
GROUP_CONCAT(c.address ORDER BY c.comid SEPARATOR ', ') AS ip_addresses,
|
||||
GROUP_CONCAT(c.macaddress ORDER BY c.comid SEPARATOR ', ') AS mac_addresses
|
||||
FROM machines m
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid
|
||||
AND c.comstypeid = (SELECT comstypeid FROM comstypes WHERE typename = 'Network_Interface' LIMIT 1)
|
||||
AND c.isactive = 1
|
||||
WHERE m.pctypeid IS NOT NULL
|
||||
GROUP BY m.machineid, m.hostname, m.machinenumber
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- vw_pc_resolved_machines: PCs with their assigned/controlled machines
|
||||
CREATE VIEW vw_pc_resolved_machines AS
|
||||
SELECT
|
||||
m1.machineid AS pc_machineid,
|
||||
m1.hostname AS pc_hostname,
|
||||
m1.machinenumber AS pc_machinenumber,
|
||||
m2.machineid AS assigned_machine_id,
|
||||
m2.machinenumber AS assigned_machine_number,
|
||||
m2.hostname AS assigned_machine_hostname,
|
||||
rt.relationshiptype
|
||||
FROM machines m1
|
||||
LEFT JOIN machinerelationships mr ON m1.machineid = mr.machineid AND mr.isactive = 1
|
||||
LEFT JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid AND rt.relationshiptype = 'Controlled By'
|
||||
LEFT JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
WHERE m1.pctypeid IS NOT NULL
|
||||
ORDER BY m1.hostname;
|
||||
|
||||
-- vw_pcs_by_hardware: PC counts grouped by manufacturer/model
|
||||
CREATE VIEW vw_pcs_by_hardware AS
|
||||
SELECT
|
||||
COALESCE(v.vendor, 'Unknown') AS manufacturer,
|
||||
COALESCE(md.modelnumber, 'Unknown') AS model,
|
||||
COUNT(m.machineid) AS count,
|
||||
GROUP_CONCAT(DISTINCT pt.typename ORDER BY pt.typename SEPARATOR ', ') AS pc_types
|
||||
FROM machines m
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
WHERE m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
GROUP BY v.vendor, md.modelnumber
|
||||
ORDER BY COUNT(m.machineid) DESC, v.vendor, md.modelnumber;
|
||||
|
||||
-- vw_shopfloor_comm_config: Shopfloor PCs with communication config
|
||||
CREATE VIEW vw_shopfloor_comm_config AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.machinenumber,
|
||||
pt.typename AS pctype,
|
||||
c.address AS ip_address,
|
||||
c.port AS port_or_socket,
|
||||
c.baud,
|
||||
c.databits,
|
||||
c.stopbits,
|
||||
c.parity,
|
||||
ct.typename AS comm_type
|
||||
FROM machines m
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isactive = 1
|
||||
LEFT JOIN comstypes ct ON c.comstypeid = ct.comstypeid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.pctypeid IS NOT NULL
|
||||
AND ct.typename IN ('IP', 'Serial')
|
||||
ORDER BY m.machinenumber, m.hostname;
|
||||
|
||||
-- vw_shopfloor_pcs: Shopfloor-type PCs with override support
|
||||
CREATE VIEW vw_shopfloor_pcs AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
COALESCE(mo.machinenumber, m.machinenumber) AS machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
m.lastupdated,
|
||||
m.lastboottime,
|
||||
DATEDIFF(NOW(), m.lastboottime) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN machineoverrides mo ON m.machineid = mo.machineid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY COALESCE(mo.machinenumber, m.machinenumber), m.hostname;
|
||||
|
||||
-- vw_standard_pcs: Standard-type PCs
|
||||
CREATE VIEW vw_standard_pcs AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser,
|
||||
m.machinenumber,
|
||||
COALESCE(os.operatingsystem, 'Unknown') AS operatingsystem,
|
||||
m.lastupdated
|
||||
FROM machines m
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Standard'
|
||||
AND m.lastupdated > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 8: Verify
|
||||
-- ============================================================================
|
||||
|
||||
-- Should only show pctype remaining
|
||||
SHOW TABLES LIKE 'pc%';
|
||||
|
||||
-- Verify views work
|
||||
SELECT 'vw_active_pcs' as view_name, COUNT(*) as cnt FROM vw_active_pcs
|
||||
UNION ALL SELECT 'vw_shopfloor_pcs', COUNT(*) FROM vw_shopfloor_pcs
|
||||
UNION ALL SELECT 'vw_standard_pcs', COUNT(*) FROM vw_standard_pcs;
|
||||
|
||||
SELECT 'Migration complete! Legacy pc tables have been dropped.' AS status;
|
||||
@@ -1,456 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- PHASE 1.0: Ensure All Machine Types Match Dev EXACTLY
|
||||
-- =============================================================================
|
||||
-- Date: 2025-11-21
|
||||
-- Purpose: Ensure production has EXACT same machine types as dev database
|
||||
-- This is CRITICAL because website code uses specific machinetypeid values
|
||||
--
|
||||
-- IMPORTANT: This script uses INSERT IGNORE with specific IDs to match dev
|
||||
--
|
||||
-- Dev Machine Types:
|
||||
-- 1-14: Equipment (existing in production)
|
||||
-- 15-20: Infrastructure (MUST ADD with exact IDs and colors)
|
||||
-- 21-25: Equipment (existing in production)
|
||||
-- 33-35: PC types (MUST ADD with exact IDs)
|
||||
--
|
||||
-- Run this as the FIRST step in Phase 1 migration
|
||||
-- Estimated Time: 30 seconds
|
||||
-- =============================================================================
|
||||
|
||||
USE shopdb;
|
||||
SET SQL_SAFE_UPDATES = 0;
|
||||
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT 'PHASE 1.0: ENSURE MACHINE TYPES MATCH DEV EXACTLY' AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT CONCAT('Start time: ', NOW()) AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 1: Check current machine types
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Current production machine types:' AS '';
|
||||
SELECT COUNT(*) AS total_machine_types FROM machinetypes;
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Existing machine types in production:' AS '';
|
||||
SELECT machinetypeid, machinetype, bgcolor, machinedescription
|
||||
FROM machinetypes
|
||||
ORDER BY machinetypeid;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 2: Check for missing machine types
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Checking for missing machine types...' AS '';
|
||||
|
||||
SET @missing_15 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 15);
|
||||
SET @missing_16 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 16);
|
||||
SET @missing_17 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 17);
|
||||
SET @missing_18 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 18);
|
||||
SET @missing_19 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 19);
|
||||
SET @missing_20 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 20);
|
||||
SET @missing_33 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 33);
|
||||
SET @missing_34 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 34);
|
||||
SET @missing_35 = NOT EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 35);
|
||||
|
||||
SELECT
|
||||
CASE WHEN @missing_15 THEN '⚠️ Missing ID 15 (Printer)' ELSE '✓ Has ID 15 (Printer)' END AS check_15,
|
||||
CASE WHEN @missing_16 THEN '⚠️ Missing ID 16 (Access Point)' ELSE '✓ Has ID 16 (Access Point)' END AS check_16,
|
||||
CASE WHEN @missing_17 THEN '⚠️ Missing ID 17 (IDF)' ELSE '✓ Has ID 17 (IDF)' END AS check_17,
|
||||
CASE WHEN @missing_18 THEN '⚠️ Missing ID 18 (Camera)' ELSE '✓ Has ID 18 (Camera)' END AS check_18,
|
||||
CASE WHEN @missing_19 THEN '⚠️ Missing ID 19 (Switch)' ELSE '✓ Has ID 19 (Switch)' END AS check_19,
|
||||
CASE WHEN @missing_20 THEN '⚠️ Missing ID 20 (Server)' ELSE '✓ Has ID 20 (Server)' END AS check_20,
|
||||
CASE WHEN @missing_33 THEN '⚠️ Missing ID 33 (Standard PC)' ELSE '✓ Has ID 33 (Standard PC)' END AS check_33,
|
||||
CASE WHEN @missing_34 THEN '⚠️ Missing ID 34 (Engineering PC)' ELSE '✓ Has ID 34 (Engineering PC)' END AS check_34,
|
||||
CASE WHEN @missing_35 THEN '⚠️ Missing ID 35 (Shopfloor PC)' ELSE '✓ Has ID 35 (Shopfloor PC)' END AS check_35;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 3: Add infrastructure machine types (EXACT match to dev)
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Adding infrastructure machine types to match dev...' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- ID 15: Printer (with bgcolor #4CAF50 - green)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
15,
|
||||
'Printer',
|
||||
b'1',
|
||||
1,
|
||||
'#4CAF50',
|
||||
'Network printer - HP, Xerox, or other print devices',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 16: Access Point (with bgcolor #2196F3 - blue)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
16,
|
||||
'Access Point',
|
||||
b'1',
|
||||
1,
|
||||
'#2196F3',
|
||||
'Wireless access point for network connectivity',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 17: IDF (with bgcolor #FF9800 - orange)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
17,
|
||||
'IDF',
|
||||
b'1',
|
||||
1,
|
||||
'#FF9800',
|
||||
'Intermediate Distribution Frame - network equipment closet',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 18: Camera (with bgcolor #F44336 - red)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
18,
|
||||
'Camera',
|
||||
b'1',
|
||||
1,
|
||||
'#F44336',
|
||||
'Security camera for facility monitoring',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 19: Switch (with bgcolor #9C27B0 - purple)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
19,
|
||||
'Switch',
|
||||
b'1',
|
||||
1,
|
||||
'#9C27B0',
|
||||
'Network switch for connectivity',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 20: Server (with bgcolor #607D8B - blue-gray)
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
20,
|
||||
'Server',
|
||||
b'1',
|
||||
1,
|
||||
'#607D8B',
|
||||
'Physical or virtual server',
|
||||
NULL
|
||||
);
|
||||
|
||||
SELECT '✓ Infrastructure machine types added (IDs 15-20)' AS status;
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 4: Deactivate old PC machine types if they exist
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Checking for old PC machine types (36-38)...' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Deactivate old machine types to prevent confusion
|
||||
UPDATE machinetypes
|
||||
SET isactive = b'0'
|
||||
WHERE machinetypeid IN (36, 37, 38);
|
||||
|
||||
SELECT CONCAT('✓ Deactivated ', ROW_COUNT(), ' old PC machine types (if they existed)') AS status;
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 5: Add PC machine types (EXACT match to dev)
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Adding PC machine types to match dev...' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- ID 33: Standard PC
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
33,
|
||||
'Standard PC',
|
||||
b'1',
|
||||
1,
|
||||
NULL,
|
||||
'Standard user workstation computer',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 34: Engineering PC
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
34,
|
||||
'Engineering PC',
|
||||
b'1',
|
||||
1,
|
||||
NULL,
|
||||
'Engineering workstation with specialized software',
|
||||
NULL
|
||||
);
|
||||
|
||||
-- ID 35: Shopfloor PC
|
||||
INSERT IGNORE INTO machinetypes (
|
||||
machinetypeid,
|
||||
machinetype,
|
||||
isactive,
|
||||
functionalaccountid,
|
||||
bgcolor,
|
||||
machinedescription,
|
||||
builddocurl
|
||||
)
|
||||
VALUES (
|
||||
35,
|
||||
'Shopfloor PC',
|
||||
b'1',
|
||||
1,
|
||||
NULL,
|
||||
'Shop floor computer for machine monitoring and control',
|
||||
NULL
|
||||
);
|
||||
|
||||
SELECT '✓ PC machine types added (IDs 33-35)' AS status;
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 6: Verification - Compare with Dev
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Verifying production matches dev...' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Check all required types exist
|
||||
SELECT 'Required machine types verification:' AS '';
|
||||
SELECT
|
||||
'ID' AS id,
|
||||
'Type' AS type,
|
||||
'Status' AS status,
|
||||
'Bgcolor' AS bgcolor
|
||||
UNION ALL
|
||||
SELECT
|
||||
'15',
|
||||
'Printer',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 15) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 15)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'16',
|
||||
'Access Point',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 16) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 16)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'17',
|
||||
'IDF',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 17) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 17)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'18',
|
||||
'Camera',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 18) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 18)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'19',
|
||||
'Switch',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 19) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 19)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'20',
|
||||
'Server',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 20) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 20)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'33',
|
||||
'Standard PC',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 33) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 33)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'34',
|
||||
'Engineering PC',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 34) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 34)
|
||||
UNION ALL
|
||||
SELECT
|
||||
'35',
|
||||
'Shopfloor PC',
|
||||
CASE WHEN EXISTS (SELECT 1 FROM machinetypes WHERE machinetypeid = 35) THEN '✓' ELSE '✗' END,
|
||||
(SELECT bgcolor FROM machinetypes WHERE machinetypeid = 35);
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Show all machine types after additions
|
||||
SELECT 'All machine types in production (after sync):' AS '';
|
||||
SELECT machinetypeid, machinetype, isactive, bgcolor, machinedescription
|
||||
FROM machinetypes
|
||||
ORDER BY machinetypeid;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Count by category
|
||||
SELECT 'Machine types by category:' AS '';
|
||||
SELECT
|
||||
CASE
|
||||
WHEN machinetypeid IN (33, 34, 35) THEN 'PC Types'
|
||||
WHEN machinetypeid IN (15, 16, 17, 18, 19, 20) THEN 'Infrastructure'
|
||||
ELSE 'Equipment'
|
||||
END AS category,
|
||||
COUNT(*) AS count,
|
||||
GROUP_CONCAT(CONCAT(machinetypeid, ':', machinetype) ORDER BY machinetypeid SEPARATOR ', ') AS types
|
||||
FROM machinetypes
|
||||
WHERE isactive = b'1'
|
||||
GROUP BY category;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 7: Final summary
|
||||
-- =============================================================================
|
||||
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT '✓✓✓ MACHINE TYPES NOW MATCH DEV EXACTLY ✓✓✓' AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Machine types summary:' AS '';
|
||||
SELECT CONCAT('Total machine types: ', COUNT(*)) AS summary FROM machinetypes;
|
||||
SELECT CONCAT('Active machine types: ', COUNT(*)) AS summary FROM machinetypes WHERE isactive = b'1';
|
||||
SELECT CONCAT('Infrastructure types (15-20): ', COUNT(*)) AS summary FROM machinetypes WHERE machinetypeid BETWEEN 15 AND 20;
|
||||
SELECT CONCAT('PC types (33-35): ', COUNT(*)) AS summary FROM machinetypes WHERE machinetypeid BETWEEN 33 AND 35;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Website color coding preserved:' AS '';
|
||||
SELECT ' - Printer (15): Green #4CAF50' AS '';
|
||||
SELECT ' - Access Point (16): Blue #2196F3' AS '';
|
||||
SELECT ' - IDF (17): Orange #FF9800' AS '';
|
||||
SELECT ' - Camera (18): Red #F44336' AS '';
|
||||
SELECT ' - Switch (19): Purple #9C27B0' AS '';
|
||||
SELECT ' - Server (20): Blue-Gray #607D8B' AS '';
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Differentiation now works:' AS '';
|
||||
SELECT ' - PCs: WHERE pctypeid IS NOT NULL' AS '';
|
||||
SELECT ' - Equipment: WHERE pctypeid IS NULL AND machinetypeid NOT IN (15-20)' AS '';
|
||||
SELECT ' - Infrastructure: WHERE pctypeid IS NULL AND machinetypeid IN (15-20)' AS '';
|
||||
|
||||
SELECT '' AS '';
|
||||
SELECT CONCAT('Completed at: ', NOW()) AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
|
||||
SET SQL_SAFE_UPDATES = 1;
|
||||
|
||||
-- =============================================================================
|
||||
-- EXPECTED DEV MACHINE TYPES (for reference)
|
||||
-- =============================================================================
|
||||
--
|
||||
-- machinetypeid | machinetype | bgcolor | Description
|
||||
-- --------------|---------------------------|-----------|---------------------------
|
||||
-- 1 | LocationOnly | #ffffff | NULL
|
||||
-- 2 | Vertical Lathe | #ffffff | NULL
|
||||
-- 3 | CMM | #ffffff | Coordinate-measuring machine
|
||||
-- 4 | Lathe | #ffffff | Okuma & Howa 2SPV80...
|
||||
-- 5 | Wax Trace | #ffffff | NULL
|
||||
-- 6 | Mill Turn | #ffffff |
|
||||
-- 7 | Intertia Welder | #ffffff | NULL
|
||||
-- 8 | Eddy Current | #ffffff | Wild Stallions...
|
||||
-- 9 | Shotpeen | #ffffff | Shot peening...
|
||||
-- 10 | Part Washer | #ffffff | NULL
|
||||
-- 11 | Grinder | NULL | NULL
|
||||
-- 12 | Broach | NULL | NULL
|
||||
-- 13 | 5-axis Mill | NULL |
|
||||
-- 14 | Furnace | NULL |
|
||||
-- 15 | Printer | #4CAF50 | Network printer... ✨ ADDED
|
||||
-- 16 | Access Point | #2196F3 | Wireless access... ✨ ADDED
|
||||
-- 17 | IDF | #FF9800 | Intermediate... ✨ ADDED
|
||||
-- 18 | Camera | #F44336 | Security camera... ✨ ADDED
|
||||
-- 19 | Switch | #9C27B0 | Network switch... ✨ ADDED
|
||||
-- 20 | Server | #607D8B | Physical or virtual... ✨ ADDED
|
||||
-- 21 | Hobbing Machine | NULL | NULL
|
||||
-- 22 | Robotic Deburring | NULL |
|
||||
-- 23 | Measuring Machine | NULL | NULL
|
||||
-- 24 | Vertical Turning Center | NULL | NULL
|
||||
-- 25 | Horizontal Machining Ctr | NULL | NULL
|
||||
-- 33 | Standard PC | NULL | Standard user... ✨ ADDED
|
||||
-- 34 | Engineering PC | NULL | Engineering... ✨ ADDED
|
||||
-- 35 | Shopfloor PC | NULL | Shop floor computer... ✨ ADDED
|
||||
--
|
||||
-- =============================================================================
|
||||
@@ -1,334 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- PHASE 1.5: Migrate Equipment IP Addresses to Communications Table
|
||||
-- =============================================================================
|
||||
-- Date: 2025-11-21
|
||||
-- Purpose: Migrate equipment (CNC, mills, lathes, etc.) IP addresses from
|
||||
-- machines.ipaddress1/ipaddress2 to communications table
|
||||
--
|
||||
-- CRITICAL: Run this AFTER Phase 1 (infrastructure created) and
|
||||
-- BEFORE removing ipaddress columns from machines table
|
||||
--
|
||||
-- Estimated Time: 1-2 minutes
|
||||
-- Records: ~275 equipment IP addresses
|
||||
-- =============================================================================
|
||||
|
||||
USE shopdb;
|
||||
SET SQL_SAFE_UPDATES = 0;
|
||||
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT 'PHASE 1.5: MIGRATE EQUIPMENT IP ADDRESSES' AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT CONCAT('Start time: ', NOW()) AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 1: Pre-migration checks
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Pre-migration checks:' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Check communications table exists
|
||||
SET @comms_exists = (
|
||||
SELECT COUNT(*) FROM information_schema.tables
|
||||
WHERE table_schema = 'shopdb' AND table_name = 'communications'
|
||||
);
|
||||
|
||||
SELECT CASE
|
||||
WHEN @comms_exists = 1 THEN '✓ Communications table exists'
|
||||
ELSE '⚠️ ERROR: Communications table not found - run Phase 1 first!'
|
||||
END AS status;
|
||||
|
||||
-- Check comstypes populated
|
||||
SET @comstypes_count = (SELECT COUNT(*) FROM comstypes WHERE typename = 'Network' OR typename = 'Network_Interface');
|
||||
|
||||
SELECT CASE
|
||||
WHEN @comstypes_count >= 1 THEN CONCAT('✓ Network comstypes exist (', @comstypes_count, ')')
|
||||
ELSE '⚠️ ERROR: Network comstypes not found - run Phase 1 first!'
|
||||
END AS status;
|
||||
|
||||
-- Check machines table has ipaddress columns
|
||||
SET @has_ip_columns = (
|
||||
SELECT COUNT(*) FROM information_schema.columns
|
||||
WHERE table_schema = 'shopdb'
|
||||
AND table_name = 'machines'
|
||||
AND column_name IN ('ipaddress1', 'ipaddress2')
|
||||
);
|
||||
|
||||
SELECT CASE
|
||||
WHEN @has_ip_columns = 2 THEN '✓ Machines table has ipaddress1/ipaddress2 columns'
|
||||
WHEN @has_ip_columns = 0 THEN '⚠️ WARNING: IP columns already removed - migration may have already run'
|
||||
ELSE '⚠️ WARNING: Only some IP columns exist'
|
||||
END AS status;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Count equipment with IP addresses
|
||||
SELECT 'Equipment IP address statistics:' AS '';
|
||||
SELECT
|
||||
'Equipment with ipaddress1' AS category,
|
||||
COUNT(*) AS count
|
||||
FROM machines
|
||||
WHERE (pctypeid IS NULL OR pctypeid = 0) -- Equipment only (not PCs)
|
||||
AND ipaddress1 IS NOT NULL
|
||||
AND ipaddress1 != ''
|
||||
AND ipaddress1 NOT IN ('X', 'TBD', 'N/A', 'x')
|
||||
UNION ALL
|
||||
SELECT
|
||||
'Equipment with ipaddress2',
|
||||
COUNT(*)
|
||||
FROM machines
|
||||
WHERE (pctypeid IS NULL OR pctypeid = 0)
|
||||
AND ipaddress2 IS NOT NULL
|
||||
AND ipaddress2 != ''
|
||||
AND ipaddress2 NOT IN ('X', 'TBD', 'N/A', 'x')
|
||||
UNION ALL
|
||||
SELECT
|
||||
'Existing equipment communications',
|
||||
COUNT(DISTINCT c.machineid)
|
||||
FROM communications c
|
||||
JOIN machines m ON c.machineid = m.machineid
|
||||
WHERE (m.pctypeid IS NULL OR m.pctypeid = 0);
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 2: Create backup of machine IP data
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Creating backup table...' AS '';
|
||||
|
||||
DROP TABLE IF EXISTS _backup_equipment_ips_phase1_5;
|
||||
CREATE TABLE _backup_equipment_ips_phase1_5 AS
|
||||
SELECT
|
||||
machineid,
|
||||
machinenumber,
|
||||
alias,
|
||||
machinetypeid,
|
||||
ipaddress1,
|
||||
ipaddress2,
|
||||
NOW() AS backup_timestamp
|
||||
FROM machines
|
||||
WHERE (pctypeid IS NULL OR pctypeid = 0) -- Equipment only
|
||||
AND (
|
||||
(ipaddress1 IS NOT NULL AND ipaddress1 != '' AND ipaddress1 NOT IN ('X', 'TBD', 'N/A', 'x'))
|
||||
OR
|
||||
(ipaddress2 IS NOT NULL AND ipaddress2 != '' AND ipaddress2 NOT IN ('X', 'TBD', 'N/A', 'x'))
|
||||
);
|
||||
|
||||
SELECT CONCAT('✓ Backup created: _backup_equipment_ips_phase1_5 (', COUNT(*), ' equipment records)') AS status
|
||||
FROM _backup_equipment_ips_phase1_5;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 3: Migrate ipaddress1 (primary interface)
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Migrating ipaddress1 (primary interface)...' AS '';
|
||||
|
||||
-- Get comstypeid for Network type
|
||||
SET @network_comstypeid = (
|
||||
SELECT comstypeid FROM comstypes
|
||||
WHERE typename IN ('Network', 'Network_Interface')
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
INSERT INTO communications (
|
||||
machineid,
|
||||
comstypeid,
|
||||
address,
|
||||
isprimary,
|
||||
interfacename,
|
||||
isactive,
|
||||
lastupdated
|
||||
)
|
||||
SELECT
|
||||
m.machineid,
|
||||
@network_comstypeid AS comstypeid,
|
||||
m.ipaddress1 AS address,
|
||||
1 AS isprimary, -- Primary interface
|
||||
'Equipment Interface 1' AS interfacename,
|
||||
1 AS isactive,
|
||||
NOW() AS lastupdated
|
||||
FROM machines m
|
||||
WHERE (m.pctypeid IS NULL OR m.pctypeid = 0) -- Equipment only (not PCs)
|
||||
AND m.ipaddress1 IS NOT NULL
|
||||
AND m.ipaddress1 != ''
|
||||
AND m.ipaddress1 NOT IN ('X', 'TBD', 'N/A', 'x') -- Exclude placeholder values
|
||||
AND NOT EXISTS (
|
||||
-- Don't insert if equipment already has a primary communication record
|
||||
SELECT 1 FROM communications c
|
||||
WHERE c.machineid = m.machineid
|
||||
AND c.isprimary = 1
|
||||
AND c.address = m.ipaddress1
|
||||
);
|
||||
|
||||
SELECT CONCAT('✓ Migrated ', ROW_COUNT(), ' primary IP addresses (ipaddress1)') AS status;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 4: Migrate ipaddress2 (secondary interface)
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Migrating ipaddress2 (secondary interface)...' AS '';
|
||||
|
||||
INSERT INTO communications (
|
||||
machineid,
|
||||
comstypeid,
|
||||
address,
|
||||
isprimary,
|
||||
interfacename,
|
||||
isactive,
|
||||
lastupdated
|
||||
)
|
||||
SELECT
|
||||
m.machineid,
|
||||
@network_comstypeid AS comstypeid,
|
||||
m.ipaddress2 AS address,
|
||||
0 AS isprimary, -- Secondary interface
|
||||
'Equipment Interface 2' AS interfacename,
|
||||
1 AS isactive,
|
||||
NOW() AS lastupdated
|
||||
FROM machines m
|
||||
WHERE (m.pctypeid IS NULL OR m.pctypeid = 0) -- Equipment only (not PCs)
|
||||
AND m.ipaddress2 IS NOT NULL
|
||||
AND m.ipaddress2 != ''
|
||||
AND m.ipaddress2 NOT IN ('X', 'TBD', 'N/A', 'x') -- Exclude placeholder values
|
||||
AND NOT EXISTS (
|
||||
-- Don't insert if equipment already has this communication record
|
||||
SELECT 1 FROM communications c
|
||||
WHERE c.machineid = m.machineid
|
||||
AND c.address = m.ipaddress2
|
||||
);
|
||||
|
||||
SELECT CONCAT('✓ Migrated ', ROW_COUNT(), ' secondary IP addresses (ipaddress2)') AS status;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 5: Verification
|
||||
-- =============================================================================
|
||||
|
||||
SELECT 'Verifying migration...' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Show summary
|
||||
SELECT 'Migration summary:' AS '';
|
||||
SELECT
|
||||
'Equipment in backup table' AS category,
|
||||
COUNT(*) AS count
|
||||
FROM _backup_equipment_ips_phase1_5
|
||||
UNION ALL
|
||||
SELECT
|
||||
'Equipment with ipaddress1 (before migration)',
|
||||
COUNT(*)
|
||||
FROM _backup_equipment_ips_phase1_5
|
||||
WHERE ipaddress1 IS NOT NULL AND ipaddress1 != '' AND ipaddress1 NOT IN ('X', 'TBD', 'N/A', 'x')
|
||||
UNION ALL
|
||||
SELECT
|
||||
'Equipment with ipaddress2 (before migration)',
|
||||
COUNT(*)
|
||||
FROM _backup_equipment_ips_phase1_5
|
||||
WHERE ipaddress2 IS NOT NULL AND ipaddress2 != '' AND ipaddress2 NOT IN ('X', 'TBD', 'N/A', 'x')
|
||||
UNION ALL
|
||||
SELECT
|
||||
'Equipment communications (after migration)',
|
||||
COUNT(DISTINCT c.machineid)
|
||||
FROM communications c
|
||||
JOIN machines m ON c.machineid = m.machineid
|
||||
WHERE (m.pctypeid IS NULL OR m.pctypeid = 0);
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Show sample of migrated equipment
|
||||
SELECT 'Sample of migrated equipment IPs:' AS '';
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.machinenumber,
|
||||
m.alias,
|
||||
COUNT(c.comid) AS interface_count,
|
||||
GROUP_CONCAT(
|
||||
CONCAT(c.address, ' (', IF(c.isprimary=1, 'Primary', 'Secondary'), ')')
|
||||
ORDER BY c.isprimary DESC
|
||||
SEPARATOR ', '
|
||||
) AS ip_addresses
|
||||
FROM machines m
|
||||
JOIN communications c ON m.machineid = c.machineid
|
||||
JOIN _backup_equipment_ips_phase1_5 b ON m.machineid = b.machineid
|
||||
WHERE (m.pctypeid IS NULL OR m.pctypeid = 0)
|
||||
GROUP BY m.machineid, m.machinenumber, m.alias
|
||||
ORDER BY m.machinenumber
|
||||
LIMIT 10;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- Check for missing migrations
|
||||
SET @missing_migrations = (
|
||||
SELECT COUNT(*)
|
||||
FROM _backup_equipment_ips_phase1_5 b
|
||||
WHERE (b.ipaddress1 IS NOT NULL AND b.ipaddress1 != '' AND b.ipaddress1 NOT IN ('X', 'TBD', 'N/A', 'x'))
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM communications c
|
||||
WHERE c.machineid = b.machineid
|
||||
)
|
||||
);
|
||||
|
||||
SELECT CASE
|
||||
WHEN @missing_migrations = 0 THEN '✓ All equipment IPs successfully migrated'
|
||||
ELSE CONCAT('⚠️ WARNING: ', @missing_migrations, ' equipment records not migrated - review logs')
|
||||
END AS status;
|
||||
|
||||
SELECT '' AS '';
|
||||
|
||||
-- =============================================================================
|
||||
-- STEP 6: Final summary
|
||||
-- =============================================================================
|
||||
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT '✓✓✓ EQUIPMENT IP MIGRATION COMPLETE ✓✓✓' AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Backup table created:' AS '';
|
||||
SELECT ' _backup_equipment_ips_phase1_5' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'Next steps:' AS '';
|
||||
SELECT ' 1. Verify equipment IPs in communications table' AS '';
|
||||
SELECT ' 2. Test application pages using equipment IPs' AS '';
|
||||
SELECT ' 3. Once verified, run remove_legacy_ip_columns.sql to drop ipaddress1/2 columns' AS '';
|
||||
SELECT '' AS '';
|
||||
|
||||
SELECT 'IMPORTANT: Keep backup table for 30 days for rollback if needed' AS '';
|
||||
|
||||
SELECT '' AS '';
|
||||
SELECT CONCAT('Completed at: ', NOW()) AS '';
|
||||
SELECT '============================================================' AS '';
|
||||
|
||||
SET SQL_SAFE_UPDATES = 1;
|
||||
|
||||
-- =============================================================================
|
||||
-- ROLLBACK PROCEDURE (if needed)
|
||||
-- =============================================================================
|
||||
--
|
||||
-- If migration needs to be rolled back:
|
||||
--
|
||||
-- 1. Delete migrated communications:
|
||||
-- DELETE c FROM communications c
|
||||
-- JOIN _backup_equipment_ips_phase1_5 b ON c.machineid = b.machineid
|
||||
-- WHERE c.interfacename LIKE 'Equipment Interface%';
|
||||
--
|
||||
-- 2. Restore ipaddress columns (if dropped):
|
||||
-- ALTER TABLE machines
|
||||
-- ADD COLUMN ipaddress1 CHAR(50) DEFAULT NULL,
|
||||
-- ADD COLUMN ipaddress2 CHAR(50) DEFAULT NULL;
|
||||
--
|
||||
-- 3. Restore IP addresses:
|
||||
-- UPDATE machines m
|
||||
-- JOIN _backup_equipment_ips_phase1_5 b ON m.machineid = b.machineid
|
||||
-- SET m.ipaddress1 = b.ipaddress1,
|
||||
-- m.ipaddress2 = b.ipaddress2;
|
||||
--
|
||||
-- =============================================================================
|
||||
@@ -1,31 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: 01_drop_migration_backup_tables.sql
|
||||
-- Purpose: Drop migration backup tables that are no longer needed
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
--
|
||||
-- IMPORTANT: Run this AFTER verifying migration is complete and stable
|
||||
-- ============================================================================
|
||||
|
||||
-- Safety check: Verify these tables exist before dropping
|
||||
SELECT 'Checking tables to drop...' AS status;
|
||||
|
||||
SELECT TABLE_NAME, TABLE_ROWS
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN ('_backup_equipment_ips_phase1_5', 'pc_backup_phase2', 'pc_to_machine_id_mapping');
|
||||
|
||||
-- ============================================================================
|
||||
-- WARNING: The following drops are destructive and cannot be undone!
|
||||
-- Make sure you have a full database backup before running.
|
||||
-- ============================================================================
|
||||
|
||||
-- Uncomment these lines when ready to execute:
|
||||
|
||||
-- DROP TABLE IF EXISTS _backup_equipment_ips_phase1_5;
|
||||
-- DROP TABLE IF EXISTS pc_backup_phase2;
|
||||
|
||||
-- NOTE: pc_to_machine_id_mapping is still used by 9 views!
|
||||
-- Must update views FIRST before dropping this table.
|
||||
-- See script 04_recreate_views.sql
|
||||
|
||||
SELECT 'Script complete. Uncomment DROP statements when ready.' AS status;
|
||||
@@ -1,35 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: 02_backup_view_definitions.sql
|
||||
-- Purpose: Export current view definitions before making changes
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
--
|
||||
-- Run this to capture current views for reference/rollback
|
||||
-- ============================================================================
|
||||
|
||||
-- View definitions that reference underscore tables (pc_to_machine_id_mapping, machine_overrides)
|
||||
-- These will need to be recreated after table renames
|
||||
|
||||
-- vw_active_pcs - uses pc_to_machine_id_mapping
|
||||
-- vw_dnc_config - uses pc_to_machine_id_mapping
|
||||
-- vw_engineer_pcs - uses pc_to_machine_id_mapping
|
||||
-- vw_pc_network_summary - uses pc_to_machine_id_mapping
|
||||
-- vw_pc_resolved_machines - uses pc_to_machine_id_mapping
|
||||
-- vw_pcs_by_hardware - uses pc_to_machine_id_mapping
|
||||
-- vw_shopfloor_comm_config - uses pc_to_machine_id_mapping
|
||||
-- vw_shopfloor_pcs - uses pc_to_machine_id_mapping AND machine_overrides
|
||||
-- vw_standard_pcs - uses pc_to_machine_id_mapping
|
||||
|
||||
-- Export commands (run from command line):
|
||||
-- mysqldump -u root -p shopdb --no-data --routines > views_backup.sql
|
||||
|
||||
-- Or query individual views:
|
||||
SELECT 'Run these SHOW CREATE VIEW commands to backup:' AS instruction;
|
||||
SHOW CREATE VIEW vw_active_pcs;
|
||||
SHOW CREATE VIEW vw_dnc_config;
|
||||
SHOW CREATE VIEW vw_engineer_pcs;
|
||||
SHOW CREATE VIEW vw_pc_network_summary;
|
||||
SHOW CREATE VIEW vw_pc_resolved_machines;
|
||||
SHOW CREATE VIEW vw_pcs_by_hardware;
|
||||
SHOW CREATE VIEW vw_shopfloor_comm_config;
|
||||
SHOW CREATE VIEW vw_shopfloor_pcs;
|
||||
SHOW CREATE VIEW vw_standard_pcs;
|
||||
@@ -1,83 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: 03_rename_tables.sql
|
||||
-- Purpose: Rename tables from snake_case to camelCase
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
--
|
||||
-- IMPORTANT:
|
||||
-- 1. Run 04_drop_and_recreate_views.sql FIRST to drop dependent views
|
||||
-- 2. Then run this script
|
||||
-- 3. Then run 04_drop_and_recreate_views.sql again to recreate views
|
||||
-- ============================================================================
|
||||
|
||||
-- Pre-flight check: Verify tables exist
|
||||
SELECT 'Verifying tables to rename exist...' AS status;
|
||||
|
||||
SELECT TABLE_NAME, TABLE_ROWS, CREATE_TIME
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN (
|
||||
'machine_overrides',
|
||||
'pc_comm_config',
|
||||
'pc_dnc_config',
|
||||
'pc_dualpath_assignments',
|
||||
'pc_network_interfaces',
|
||||
'usb_checkouts'
|
||||
);
|
||||
|
||||
-- ============================================================================
|
||||
-- TABLE RENAMES
|
||||
-- ============================================================================
|
||||
|
||||
-- Rename: machine_overrides -> machineoverrides
|
||||
RENAME TABLE machine_overrides TO machineoverrides;
|
||||
|
||||
-- Rename: pc_comm_config -> commconfig
|
||||
RENAME TABLE pc_comm_config TO commconfig;
|
||||
|
||||
-- Rename: pc_dnc_config -> dncconfig
|
||||
RENAME TABLE pc_dnc_config TO dncconfig;
|
||||
|
||||
-- Rename: pc_dualpath_assignments -> dualpathassignments
|
||||
RENAME TABLE pc_dualpath_assignments TO dualpathassignments;
|
||||
|
||||
-- Rename: pc_network_interfaces -> networkinterfaces
|
||||
RENAME TABLE pc_network_interfaces TO networkinterfaces;
|
||||
|
||||
-- Rename: usb_checkouts -> usbcheckouts
|
||||
RENAME TABLE usb_checkouts TO usbcheckouts;
|
||||
|
||||
-- ============================================================================
|
||||
-- VERIFICATION
|
||||
-- ============================================================================
|
||||
|
||||
SELECT 'Verifying renames completed...' AS status;
|
||||
|
||||
SELECT TABLE_NAME, TABLE_ROWS
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN (
|
||||
'machineoverrides',
|
||||
'commconfig',
|
||||
'dncconfig',
|
||||
'dualpathassignments',
|
||||
'networkinterfaces',
|
||||
'usbcheckouts'
|
||||
);
|
||||
|
||||
-- Check old names no longer exist
|
||||
SELECT 'Checking old table names are gone...' AS status;
|
||||
|
||||
SELECT TABLE_NAME
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN (
|
||||
'machine_overrides',
|
||||
'pc_comm_config',
|
||||
'pc_dnc_config',
|
||||
'pc_dualpath_assignments',
|
||||
'pc_network_interfaces',
|
||||
'usb_checkouts'
|
||||
);
|
||||
-- Should return 0 rows
|
||||
|
||||
SELECT 'Table renames complete!' AS status;
|
||||
@@ -1,264 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: 04_drop_and_recreate_views.sql
|
||||
-- Purpose: Drop views that reference underscore tables, recreate with new names
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
--
|
||||
-- IMPORTANT: This is a SINGLE script. Run it all at once in MySQL Workbench
|
||||
-- or via mysql command line. Do NOT split it up.
|
||||
--
|
||||
-- USAGE ORDER:
|
||||
-- 1. Run this entire script FIRST (drops old views, creates new ones)
|
||||
-- 2. Then run 03_rename_tables.sql
|
||||
-- 3. The views will error until tables are renamed - that's expected
|
||||
--
|
||||
-- OR for safer approach:
|
||||
-- 1. Run just the DROP statements
|
||||
-- 2. Run 03_rename_tables.sql
|
||||
-- 3. Run just the CREATE statements
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- PART 1: DROP VIEWS
|
||||
-- ============================================================================
|
||||
|
||||
DROP VIEW IF EXISTS vw_active_pcs;
|
||||
DROP VIEW IF EXISTS vw_dnc_config;
|
||||
DROP VIEW IF EXISTS vw_engineer_pcs;
|
||||
DROP VIEW IF EXISTS vw_pc_network_summary;
|
||||
DROP VIEW IF EXISTS vw_pc_resolved_machines;
|
||||
DROP VIEW IF EXISTS vw_pcs_by_hardware;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_comm_config;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_pcs;
|
||||
DROP VIEW IF EXISTS vw_standard_pcs;
|
||||
|
||||
-- ============================================================================
|
||||
-- PART 2: RECREATE VIEWS
|
||||
-- Note: These reference the NEW table name: machineoverrides (not machine_overrides)
|
||||
-- Note: pc_to_machine_id_mapping is kept for pcid->machineid mapping
|
||||
-- ============================================================================
|
||||
|
||||
-- vw_active_pcs
|
||||
CREATE VIEW vw_active_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.serialnumber AS serialnumber,
|
||||
COALESCE(v.vendor,'Unknown') AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser AS loggedinuser,
|
||||
m.machinenumber AS machinenumber,
|
||||
COALESCE(os.operatingsystem,'Unknown') AS operatingsystem,
|
||||
COALESCE(pt.typename,'Unknown') AS pctype,
|
||||
COALESCE(pt.description,'Unknown') AS typedescription,
|
||||
CASE
|
||||
WHEN w.enddate IS NULL THEN 'Unknown'
|
||||
WHEN w.enddate < CURDATE() THEN 'Expired'
|
||||
WHEN w.enddate < (CURDATE() + INTERVAL 90 DAY) THEN 'Expiring Soon'
|
||||
ELSE 'Active'
|
||||
END AS warrantystatus,
|
||||
w.enddate AS warrantyenddate,
|
||||
CASE
|
||||
WHEN w.enddate IS NULL THEN NULL
|
||||
ELSE (TO_DAYS(w.enddate) - TO_DAYS(CURDATE()))
|
||||
END AS warrantydaysremaining,
|
||||
m.lastupdated AS lastupdated,
|
||||
(TO_DAYS(NOW()) - TO_DAYS(m.lastupdated)) AS daysold,
|
||||
m.lastboottime AS lastboottime,
|
||||
(TO_DAYS(NOW()) - TO_DAYS(m.lastboottime)) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
LEFT JOIN warranties w ON m.machineid = w.machineid
|
||||
WHERE m.lastupdated > (NOW() - INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL;
|
||||
|
||||
-- vw_dnc_config
|
||||
CREATE VIEW vw_dnc_config AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.machinenumber AS machinenumber,
|
||||
c.address AS ip_address,
|
||||
c.port AS socket,
|
||||
c.settings AS config_settings,
|
||||
ct.typename AS comm_type
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isactive = 1
|
||||
LEFT JOIN comstypes ct ON c.comstypeid = ct.comstypeid
|
||||
WHERE m.pctypeid IS NOT NULL
|
||||
AND ct.typename IN ('IP','Serial')
|
||||
ORDER BY m.hostname, ct.typename;
|
||||
|
||||
-- vw_engineer_pcs
|
||||
CREATE VIEW vw_engineer_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.serialnumber AS serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser AS loggedinuser,
|
||||
m.machinenumber AS machinenumber,
|
||||
COALESCE(os.operatingsystem,'Unknown') AS operatingsystem,
|
||||
m.lastupdated AS lastupdated
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Engineer'
|
||||
AND m.lastupdated > (NOW() - INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- vw_pc_network_summary
|
||||
CREATE VIEW vw_pc_network_summary AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.machinenumber AS machinenumber,
|
||||
COUNT(c.comid) AS interface_count,
|
||||
GROUP_CONCAT(c.address ORDER BY c.comid ASC SEPARATOR ', ') AS ip_addresses,
|
||||
GROUP_CONCAT(c.macaddress ORDER BY c.comid ASC SEPARATOR ', ') AS mac_addresses
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid
|
||||
AND c.comstypeid = (SELECT comstypeid FROM comstypes WHERE typename = 'Network_Interface' LIMIT 1)
|
||||
AND c.isactive = 1
|
||||
WHERE m.pctypeid IS NOT NULL
|
||||
GROUP BY pcmap.pcid, m.hostname, m.machinenumber
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- vw_pc_resolved_machines
|
||||
CREATE VIEW vw_pc_resolved_machines AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m1.machineid AS pc_machineid,
|
||||
m1.hostname AS pc_hostname,
|
||||
m1.machinenumber AS pc_machinenumber,
|
||||
m2.machineid AS assigned_machine_id,
|
||||
m2.machinenumber AS assigned_machine_number,
|
||||
m2.hostname AS assigned_machine_hostname,
|
||||
rt.relationshiptype AS relationshiptype
|
||||
FROM machines m1
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m1.machineid = pcmap.new_machineid
|
||||
LEFT JOIN machinerelationships mr ON m1.machineid = mr.machineid AND mr.isactive = 1
|
||||
LEFT JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid AND rt.relationshiptype = 'Controlled By'
|
||||
LEFT JOIN machines m2 ON mr.related_machineid = m2.machineid
|
||||
WHERE m1.pctypeid IS NOT NULL
|
||||
ORDER BY m1.hostname;
|
||||
|
||||
-- vw_pcs_by_hardware
|
||||
CREATE VIEW vw_pcs_by_hardware AS
|
||||
SELECT
|
||||
COALESCE(v.vendor,'Unknown') AS manufacturer,
|
||||
COALESCE(md.modelnumber,'Unknown') AS model,
|
||||
COUNT(m.machineid) AS count,
|
||||
GROUP_CONCAT(DISTINCT pt.typename ORDER BY pt.typename ASC SEPARATOR ', ') AS pc_types
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
WHERE m.lastupdated > (NOW() - INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
GROUP BY v.vendor, md.modelnumber
|
||||
ORDER BY COUNT(m.machineid) DESC, v.vendor, md.modelnumber;
|
||||
|
||||
-- vw_shopfloor_comm_config
|
||||
CREATE VIEW vw_shopfloor_comm_config AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.machinenumber AS machinenumber,
|
||||
pt.typename AS pctype,
|
||||
c.address AS ip_address,
|
||||
c.port AS port_or_socket,
|
||||
c.baud AS baud,
|
||||
c.databits AS databits,
|
||||
c.stopbits AS stopbits,
|
||||
c.parity AS parity,
|
||||
ct.typename AS comm_type
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN communications c ON m.machineid = c.machineid AND c.isactive = 1
|
||||
LEFT JOIN comstypes ct ON c.comstypeid = ct.comstypeid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.pctypeid IS NOT NULL
|
||||
AND ct.typename IN ('IP','Serial')
|
||||
ORDER BY m.machinenumber, m.hostname;
|
||||
|
||||
-- vw_shopfloor_pcs (uses machineoverrides - NEW NAME)
|
||||
CREATE VIEW vw_shopfloor_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.serialnumber AS serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser AS loggedinuser,
|
||||
COALESCE(CONVERT(mo.machinenumber USING utf8mb4), CONVERT(m.machinenumber USING utf8mb4)) AS machinenumber,
|
||||
COALESCE(os.operatingsystem,'Unknown') AS operatingsystem,
|
||||
m.lastupdated AS lastupdated,
|
||||
m.lastboottime AS lastboottime,
|
||||
(TO_DAYS(NOW()) - TO_DAYS(m.lastboottime)) AS uptime_days
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN machineoverrides mo ON pcmap.pcid = mo.pcid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Shopfloor'
|
||||
AND m.lastupdated > (NOW() - INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY COALESCE(CONVERT(mo.machinenumber USING utf8mb4), CONVERT(m.machinenumber USING utf8mb4)), m.hostname;
|
||||
|
||||
-- vw_standard_pcs
|
||||
CREATE VIEW vw_standard_pcs AS
|
||||
SELECT
|
||||
pcmap.pcid AS pcid,
|
||||
m.hostname AS hostname,
|
||||
m.serialnumber AS serialnumber,
|
||||
v.vendor AS manufacturer,
|
||||
md.modelnumber AS model,
|
||||
m.loggedinuser AS loggedinuser,
|
||||
m.machinenumber AS machinenumber,
|
||||
COALESCE(os.operatingsystem,'Unknown') AS operatingsystem,
|
||||
m.lastupdated AS lastupdated
|
||||
FROM machines m
|
||||
JOIN pc_to_machine_id_mapping pcmap ON m.machineid = pcmap.new_machineid
|
||||
JOIN pctype pt ON m.pctypeid = pt.pctypeid
|
||||
LEFT JOIN models md ON m.modelnumberid = md.modelnumberid
|
||||
LEFT JOIN vendors v ON md.vendorid = v.vendorid
|
||||
LEFT JOIN operatingsystems os ON m.osid = os.osid
|
||||
WHERE pt.typename = 'Standard'
|
||||
AND m.lastupdated > (NOW() - INTERVAL 30 DAY)
|
||||
AND m.pctypeid IS NOT NULL
|
||||
ORDER BY m.hostname;
|
||||
|
||||
-- ============================================================================
|
||||
-- VERIFICATION
|
||||
-- ============================================================================
|
||||
|
||||
SELECT 'Views recreated successfully!' AS status;
|
||||
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME IN (
|
||||
'vw_active_pcs',
|
||||
'vw_dnc_config',
|
||||
'vw_engineer_pcs',
|
||||
'vw_pc_network_summary',
|
||||
'vw_pc_resolved_machines',
|
||||
'vw_pcs_by_hardware',
|
||||
'vw_shopfloor_comm_config',
|
||||
'vw_shopfloor_pcs',
|
||||
'vw_standard_pcs'
|
||||
)
|
||||
ORDER BY TABLE_NAME;
|
||||
@@ -1,124 +0,0 @@
|
||||
# ============================================================================
|
||||
# Script: 05_update_asp_files.ps1
|
||||
# Purpose: Update ASP files to use new table names
|
||||
# Target: ShopDB ASP files on Windows
|
||||
#
|
||||
# USAGE:
|
||||
# cd C:\path\to\shopdb
|
||||
# .\sql\naming_convention_fix\05_update_asp_files.ps1
|
||||
# .\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[switch]$Execute
|
||||
)
|
||||
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host "ASP File Table Name Updates" -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Define replacements (old -> new)
|
||||
$replacements = @{
|
||||
"machine_overrides" = "machineoverrides"
|
||||
"pc_comm_config" = "commconfig"
|
||||
"pc_dnc_config" = "dncconfig"
|
||||
"pc_dualpath_assignments" = "dualpathassignments"
|
||||
"pc_network_interfaces" = "networkinterfaces"
|
||||
"usb_checkouts" = "usbcheckouts"
|
||||
}
|
||||
|
||||
# Files to update (from impact analysis)
|
||||
$fileTables = @{
|
||||
"api.asp" = @("pc_comm_config", "pc_dnc_config")
|
||||
"displaypc.asp" = @("pc_network_interfaces")
|
||||
"displaysubnet.asp" = @("pc_network_interfaces")
|
||||
"displaymachine.asp" = @("pc_network_interfaces")
|
||||
"usb_history.asp" = @("usb_checkouts")
|
||||
"savecheckin_usb.asp" = @("usb_checkouts")
|
||||
"displayprofile.asp" = @("usb_checkouts")
|
||||
"displayusb.asp" = @("usb_checkouts")
|
||||
"savecheckout_usb.asp" = @("usb_checkouts")
|
||||
"api_usb.asp" = @("usb_checkouts")
|
||||
}
|
||||
|
||||
Write-Host "Changes to be made:" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
foreach ($file in $fileTables.Keys) {
|
||||
$filepath = Join-Path $PSScriptRoot "..\..\$file"
|
||||
|
||||
if (Test-Path $filepath) {
|
||||
$content = Get-Content $filepath -Raw
|
||||
$tables = $fileTables[$file]
|
||||
|
||||
Write-Host "--- $file ---" -ForegroundColor Green
|
||||
|
||||
foreach ($table in $tables) {
|
||||
$newName = $replacements[$table]
|
||||
$matches = ([regex]::Matches($content, [regex]::Escape($table))).Count
|
||||
|
||||
if ($matches -gt 0) {
|
||||
Write-Host " $table -> $newName ($matches occurrences)" -ForegroundColor White
|
||||
|
||||
# Show first few matches with line numbers
|
||||
$lines = Get-Content $filepath
|
||||
$lineNum = 0
|
||||
$shown = 0
|
||||
foreach ($line in $lines) {
|
||||
$lineNum++
|
||||
if ($line -match [regex]::Escape($table) -and $shown -lt 3) {
|
||||
Write-Host " Line $lineNum : $($line.Trim().Substring(0, [Math]::Min(80, $line.Trim().Length)))" -ForegroundColor Gray
|
||||
$shown++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
else {
|
||||
Write-Host "WARNING: $file not found!" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
if ($Execute) {
|
||||
Write-Host ""
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host "EXECUTING CHANGES..." -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
foreach ($file in $fileTables.Keys) {
|
||||
$filepath = Join-Path $PSScriptRoot "..\..\$file"
|
||||
|
||||
if (Test-Path $filepath) {
|
||||
$content = Get-Content $filepath -Raw
|
||||
$tables = $fileTables[$file]
|
||||
$modified = $false
|
||||
|
||||
foreach ($table in $tables) {
|
||||
$newName = $replacements[$table]
|
||||
if ($content -match [regex]::Escape($table)) {
|
||||
$content = $content -replace [regex]::Escape($table), $newName
|
||||
$modified = $true
|
||||
Write-Host "Updated $file : $table -> $newName" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
if ($modified) {
|
||||
Set-Content -Path $filepath -Value $content -NoNewline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "ASP files updated successfully!" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host ""
|
||||
Write-Host "============================================" -ForegroundColor Yellow
|
||||
Write-Host "DRY RUN COMPLETE" -ForegroundColor Yellow
|
||||
Write-Host "============================================" -ForegroundColor Yellow
|
||||
Write-Host "To apply changes, run:" -ForegroundColor White
|
||||
Write-Host " .\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute" -ForegroundColor Cyan
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
# ============================================================================
|
||||
# Script: 06_update_docs.ps1
|
||||
# Purpose: Update documentation files to reference new table names
|
||||
# Target: ShopDB markdown files on Windows
|
||||
#
|
||||
# USAGE:
|
||||
# cd C:\path\to\shopdb
|
||||
# .\sql\naming_convention_fix\06_update_docs.ps1
|
||||
# .\sql\naming_convention_fix\06_update_docs.ps1 -Execute
|
||||
#
|
||||
# This is lower priority - docs can be updated anytime after migration
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[switch]$Execute
|
||||
)
|
||||
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host "Documentation Table Name Updates" -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Define replacements
|
||||
$replacements = @{
|
||||
"machine_overrides" = "machineoverrides"
|
||||
"pc_comm_config" = "commconfig"
|
||||
"pc_dnc_config" = "dncconfig"
|
||||
"pc_dualpath_assignments" = "dualpathassignments"
|
||||
"pc_network_interfaces" = "networkinterfaces"
|
||||
"usb_checkouts" = "usbcheckouts"
|
||||
}
|
||||
|
||||
# Get the shopdb root directory (two levels up from script location)
|
||||
$shopdbRoot = Join-Path $PSScriptRoot "..\..\"
|
||||
|
||||
Write-Host "Searching for documentation files with old table names..." -ForegroundColor Yellow
|
||||
Write-Host "Directory: $shopdbRoot" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
# Find all markdown files
|
||||
$mdFiles = Get-ChildItem -Path $shopdbRoot -Filter "*.md" -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
$filesToUpdate = @{}
|
||||
|
||||
foreach ($oldName in $replacements.Keys) {
|
||||
$newName = $replacements[$oldName]
|
||||
Write-Host "--- $oldName -> $newName ---" -ForegroundColor Green
|
||||
|
||||
$matchingFiles = @()
|
||||
|
||||
foreach ($file in $mdFiles) {
|
||||
$content = Get-Content $file.FullName -Raw -ErrorAction SilentlyContinue
|
||||
if ($content -match [regex]::Escape($oldName)) {
|
||||
$count = ([regex]::Matches($content, [regex]::Escape($oldName))).Count
|
||||
$relativePath = $file.FullName.Replace((Resolve-Path $shopdbRoot).Path, "")
|
||||
Write-Host " $relativePath ($count occurrences)" -ForegroundColor White
|
||||
|
||||
if (-not $filesToUpdate.ContainsKey($file.FullName)) {
|
||||
$filesToUpdate[$file.FullName] = @()
|
||||
}
|
||||
$filesToUpdate[$file.FullName] += $oldName
|
||||
}
|
||||
}
|
||||
|
||||
if ($matchingFiles.Count -eq 0) {
|
||||
# Already printed matches above
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
Write-Host "Total files to update: $($filesToUpdate.Count)" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
if ($Execute) {
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host "EXECUTING CHANGES..." -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
foreach ($filePath in $filesToUpdate.Keys) {
|
||||
$content = Get-Content $filePath -Raw
|
||||
|
||||
foreach ($oldName in $replacements.Keys) {
|
||||
$newName = $replacements[$oldName]
|
||||
if ($content -match [regex]::Escape($oldName)) {
|
||||
$content = $content -replace [regex]::Escape($oldName), $newName
|
||||
}
|
||||
}
|
||||
|
||||
Set-Content -Path $filePath -Value $content -NoNewline
|
||||
$relativePath = $filePath.Replace((Resolve-Path $shopdbRoot).Path, "")
|
||||
Write-Host "Updated: $relativePath" -ForegroundColor Green
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Documentation updated successfully!" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "============================================" -ForegroundColor Yellow
|
||||
Write-Host "DRY RUN COMPLETE" -ForegroundColor Yellow
|
||||
Write-Host "============================================" -ForegroundColor Yellow
|
||||
Write-Host "To apply changes, run:" -ForegroundColor White
|
||||
Write-Host " .\sql\naming_convention_fix\06_update_docs.ps1 -Execute" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "NOTE: Documentation updates are low priority." -ForegroundColor Gray
|
||||
Write-Host " Focus on database and ASP changes first." -ForegroundColor Gray
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
-- ============================================================================
|
||||
-- Script: 07_fix_compliance_columns.sql
|
||||
-- Purpose: Rename snake_case columns to camelCase in compliance tables
|
||||
-- Target: MySQL 5.6 (dev and production)
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 1: DROP DEPENDENT VIEW
|
||||
-- ============================================================================
|
||||
|
||||
DROP VIEW IF EXISTS vw_compliance_summary;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 2: RENAME COMPLIANCE TABLE COLUMNS
|
||||
-- ============================================================================
|
||||
|
||||
-- compliance table column renames
|
||||
ALTER TABLE compliance
|
||||
CHANGE COLUMN scan_date scandate datetime,
|
||||
CHANGE COLUMN deployment_notes deploymentnotes text,
|
||||
CHANGE COLUMN is_third_party_managed isthirdpartymanaged enum('Yes','No','NA') DEFAULT 'NA',
|
||||
CHANGE COLUMN third_party_manager thirdpartymanager varchar(255),
|
||||
CHANGE COLUMN ot_asset_system otassetsystem varchar(255),
|
||||
CHANGE COLUMN ot_asset_device otassetdevice varchar(255),
|
||||
CHANGE COLUMN ot_asset_location otassetlocation varchar(255),
|
||||
CHANGE COLUMN ot_asset_device_type otassetdevicetype varchar(100),
|
||||
CHANGE COLUMN ot_asset_category otassetcategory varchar(100),
|
||||
CHANGE COLUMN ot_asset_last_seen otassetlastseen datetime,
|
||||
CHANGE COLUMN ot_asset_ip_source otassetipsource varchar(100),
|
||||
CHANGE COLUMN is_compliant iscompliant tinyint(1),
|
||||
CHANGE COLUMN compliance_notes compliancenotes text;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 3: RENAME COMPLIANCESCANS TABLE COLUMNS
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE compliancescans
|
||||
CHANGE COLUMN scan_name scanname varchar(255),
|
||||
CHANGE COLUMN scan_date scandate datetime NOT NULL,
|
||||
CHANGE COLUMN scan_result scanresult enum('Pass','Fail','Warning','Info') DEFAULT 'Info',
|
||||
CHANGE COLUMN scan_details scandetails text;
|
||||
|
||||
-- ============================================================================
|
||||
-- STEP 4: RECREATE VIEW WITH NEW COLUMN NAMES
|
||||
-- ============================================================================
|
||||
|
||||
CREATE VIEW vw_compliance_summary AS
|
||||
SELECT
|
||||
m.machineid,
|
||||
m.machinenumber,
|
||||
m.hostname,
|
||||
m.serialnumber,
|
||||
c.scan,
|
||||
c.scandate,
|
||||
c.isthirdpartymanaged,
|
||||
c.thirdpartymanager,
|
||||
c.mft,
|
||||
c.iscompliant,
|
||||
c.deploymentnotes,
|
||||
c.otassetsystem,
|
||||
c.otassetdevice,
|
||||
c.otassetlocation,
|
||||
(TO_DAYS(CURDATE()) - TO_DAYS(c.scandate)) AS days_since_scan,
|
||||
CASE
|
||||
WHEN c.scandate IS NULL THEN 'Never Scanned'
|
||||
WHEN c.scandate < (CURDATE() - INTERVAL 90 DAY) THEN 'Scan Overdue'
|
||||
WHEN c.scandate < (CURDATE() - INTERVAL 30 DAY) THEN 'Scan Due Soon'
|
||||
ELSE 'Scan Current'
|
||||
END AS scan_status
|
||||
FROM machines m
|
||||
LEFT JOIN compliance c ON m.machineid = c.machineid
|
||||
WHERE m.isactive = 1;
|
||||
|
||||
-- ============================================================================
|
||||
-- VERIFICATION
|
||||
-- ============================================================================
|
||||
|
||||
SELECT 'Compliance table columns after rename:' AS status;
|
||||
SHOW COLUMNS FROM compliance;
|
||||
|
||||
SELECT 'Compliancescans table columns after rename:' AS status;
|
||||
SHOW COLUMNS FROM compliancescans;
|
||||
|
||||
SELECT 'View test:' AS status;
|
||||
SELECT COUNT(*) AS row_count FROM vw_compliance_summary;
|
||||
|
||||
SELECT 'Column rename complete!' AS status;
|
||||
@@ -1,93 +0,0 @@
|
||||
# ASP Filename Rename Plan
|
||||
|
||||
## Naming Convention
|
||||
- All lowercase
|
||||
- No underscores (use concatenated words like `displaymachine.asp`)
|
||||
- Pattern: `[action][entity].asp` or `[action][entity]direct.asp` for form handlers
|
||||
|
||||
## Files to Rename
|
||||
|
||||
### Remove underscores from direct handlers
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| addlink_direct.asp | addlinkdirect.asp |
|
||||
| addsubnetbackend_direct.asp | addsubnetbackenddirect.asp |
|
||||
| editapplication_direct.asp | editapplicationdirect.asp |
|
||||
| saveapplication_direct.asp | saveapplicationdirect.asp |
|
||||
| savedevice_direct.asp | savedevicedirect.asp |
|
||||
| savemachine_direct.asp | savemachinedirect.asp |
|
||||
| savemodel_direct.asp | savemodeldirect.asp |
|
||||
| save_network_device.asp | savenetworkdevice.asp |
|
||||
| savenotification_direct.asp | savenotificationdirect.asp |
|
||||
| saveprinter_direct.asp | saveprinterdirect.asp |
|
||||
| saveusb_direct.asp | saveusbdirect.asp |
|
||||
| savevendor_direct.asp | savevendordirect.asp |
|
||||
| updatedevice_direct.asp | updatedevicedirect.asp |
|
||||
| updatelink_direct.asp | updatelinkdirect.asp |
|
||||
| updatenotification_direct.asp | updatenotificationdirect.asp |
|
||||
| updatepc_direct.asp | updatepcdirect.asp |
|
||||
| updatesubnet_direct.asp | updatesubnetdirect.asp |
|
||||
|
||||
### Remove underscores from USB files
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| checkin_usb.asp | checkinusb.asp |
|
||||
| checkout_usb.asp | checkoutusb.asp |
|
||||
| savecheckin_usb.asp | savecheckinusb.asp |
|
||||
| savecheckout_usb.asp | savecheckoutusb.asp |
|
||||
| usb_history.asp | usbhistory.asp |
|
||||
|
||||
### Remove underscores from API files
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| api_businessunits.asp | apibusinessunits.asp |
|
||||
| api_printers.asp | apiprinters.asp |
|
||||
| api_shopfloor.asp | apishopfloor.asp |
|
||||
| api_usb.asp | apiusb.asp |
|
||||
|
||||
### Remove underscores from machine/map files
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| machine_edit.asp | machineedit.asp |
|
||||
| machine_map.asp | machinemap.asp |
|
||||
| machine_map_editor.asp | machinemapeditor.asp |
|
||||
| network_devices.asp | networkdevices.asp |
|
||||
| network_map.asp | networkmap.asp |
|
||||
| network_map_debug.asp | networkmapdebug.asp |
|
||||
|
||||
### Remove underscores from printer files
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| check_duplicate_printers.asp | checkduplicateprinters.asp |
|
||||
| check_printer_machines_count.asp | checkprintermachinescount.asp |
|
||||
| cleanup_duplicate_printers_execute.asp | cleanupduplicateprintersexecute.asp |
|
||||
| insert_all_printer_machines.asp | insertallprintermachines.asp |
|
||||
| install_printer.asp | installprinter.asp |
|
||||
| printer_installer_map.asp | printerinstallermap.asp |
|
||||
| printer_links_generator.asp | printerlinksgenerator.asp |
|
||||
| printer_lookup.asp | printerlookup.asp |
|
||||
|
||||
### Remove underscores from other files
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| admin_clear_cache.asp | adminclearcache.asp |
|
||||
| bulk_update_notification_types.asp | bulkupdatenotificationtypes.asp |
|
||||
| displaylocation_device.asp | displaylocationdevice.asp |
|
||||
| quickadd_application.asp | quickaddapplication.asp |
|
||||
| refresh_zabbix_cache.asp | refreshzabbixcache.asp |
|
||||
|
||||
### Fix typo
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| editmacine.asp | (DELETE - duplicate of editmachine.asp) |
|
||||
|
||||
### Test files to DELETE (not rename)
|
||||
- editmachine_test.asp
|
||||
- test_asp.asp
|
||||
- test_db.asp
|
||||
- test_switch_query.asp
|
||||
- test_with_includes.asp
|
||||
|
||||
## Total Changes
|
||||
- **49 files to rename**
|
||||
- **6 files to delete**
|
||||
@@ -1,200 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Renames ASP files to remove underscores and updates all internal references.
|
||||
|
||||
.DESCRIPTION
|
||||
This script:
|
||||
1. Renames ASP files from snake_case to concatenated lowercase
|
||||
2. Updates all references in ASP, JS, and include files
|
||||
3. Deletes test files
|
||||
|
||||
.PARAMETER Execute
|
||||
Actually perform the renames. Without this, runs in dry-run mode.
|
||||
|
||||
.EXAMPLE
|
||||
.\09_rename_asp_files.ps1 # Dry run - shows what would change
|
||||
.\09_rename_asp_files.ps1 -Execute # Actually performs the renames
|
||||
#>
|
||||
|
||||
param(
|
||||
[switch]$Execute
|
||||
)
|
||||
|
||||
$shopdbPath = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
|
||||
# Define rename mappings (old -> new)
|
||||
$renames = @{
|
||||
# Direct handlers
|
||||
"addlink_direct.asp" = "addlinkdirect.asp"
|
||||
"addsubnetbackend_direct.asp" = "addsubnetbackenddirect.asp"
|
||||
"editapplication_direct.asp" = "editapplicationdirect.asp"
|
||||
"saveapplication_direct.asp" = "saveapplicationdirect.asp"
|
||||
"savedevice_direct.asp" = "savedevicedirect.asp"
|
||||
"savemachine_direct.asp" = "savemachinedirect.asp"
|
||||
"savemodel_direct.asp" = "savemodeldirect.asp"
|
||||
"save_network_device.asp" = "savenetworkdevice.asp"
|
||||
"savenotification_direct.asp" = "savenotificationdirect.asp"
|
||||
"saveprinter_direct.asp" = "saveprinterdirect.asp"
|
||||
"saveusb_direct.asp" = "saveusbdirect.asp"
|
||||
"savevendor_direct.asp" = "savevendordirect.asp"
|
||||
"updatedevice_direct.asp" = "updatedevicedirect.asp"
|
||||
"updatelink_direct.asp" = "updatelinkdirect.asp"
|
||||
"updatenotification_direct.asp" = "updatenotificationdirect.asp"
|
||||
"updatepc_direct.asp" = "updatepcdirect.asp"
|
||||
"updatesubnet_direct.asp" = "updatesubnetdirect.asp"
|
||||
|
||||
# USB files
|
||||
"checkin_usb.asp" = "checkinusb.asp"
|
||||
"checkout_usb.asp" = "checkoutusb.asp"
|
||||
"savecheckin_usb.asp" = "savecheckinusb.asp"
|
||||
"savecheckout_usb.asp" = "savecheckoutusb.asp"
|
||||
"usb_history.asp" = "usbhistory.asp"
|
||||
|
||||
# API files
|
||||
"api_businessunits.asp" = "apibusinessunits.asp"
|
||||
"api_printers.asp" = "apiprinters.asp"
|
||||
"api_shopfloor.asp" = "apishopfloor.asp"
|
||||
"api_usb.asp" = "apiusb.asp"
|
||||
|
||||
# Machine/map files
|
||||
"machine_edit.asp" = "machineedit.asp"
|
||||
"machine_map.asp" = "machinemap.asp"
|
||||
"machine_map_editor.asp" = "machinemapeditor.asp"
|
||||
"network_devices.asp" = "networkdevices.asp"
|
||||
"network_map.asp" = "networkmap.asp"
|
||||
"network_map_debug.asp" = "networkmapdebug.asp"
|
||||
|
||||
# Printer files
|
||||
"check_duplicate_printers.asp" = "checkduplicateprinters.asp"
|
||||
"check_printer_machines_count.asp" = "checkprintermachinescount.asp"
|
||||
"cleanup_duplicate_printers_execute.asp" = "cleanupduplicateprintersexecute.asp"
|
||||
"insert_all_printer_machines.asp" = "insertallprintermachines.asp"
|
||||
"install_printer.asp" = "installprinter.asp"
|
||||
"printer_installer_map.asp" = "printerinstallermap.asp"
|
||||
"printer_links_generator.asp" = "printerlinksgenerator.asp"
|
||||
"printer_lookup.asp" = "printerlookup.asp"
|
||||
|
||||
# Other files
|
||||
"admin_clear_cache.asp" = "adminclearcache.asp"
|
||||
"bulk_update_notification_types.asp" = "bulkupdatenotificationtypes.asp"
|
||||
"displaylocation_device.asp" = "displaylocationdevice.asp"
|
||||
"quickadd_application.asp" = "quickaddapplication.asp"
|
||||
"refresh_zabbix_cache.asp" = "refreshzabbixcache.asp"
|
||||
}
|
||||
|
||||
# Files to delete
|
||||
$deleteFiles = @(
|
||||
"editmacine.asp"
|
||||
"editmachine_test.asp"
|
||||
"test_asp.asp"
|
||||
"test_db.asp"
|
||||
"test_switch_query.asp"
|
||||
"test_with_includes.asp"
|
||||
)
|
||||
|
||||
Write-Host "ASP File Rename Script" -ForegroundColor Cyan
|
||||
Write-Host "======================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
if (-not $Execute) {
|
||||
Write-Host "DRY RUN MODE - No changes will be made" -ForegroundColor Yellow
|
||||
Write-Host "Run with -Execute to apply changes" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# Get all files to search for references
|
||||
$searchFiles = @()
|
||||
$searchFiles += Get-ChildItem -Path $shopdbPath -Filter "*.asp" -File
|
||||
$searchFiles += Get-ChildItem -Path "$shopdbPath\includes" -Filter "*.asp" -File -ErrorAction SilentlyContinue
|
||||
$searchFiles += Get-ChildItem -Path "$shopdbPath\js" -Filter "*.js" -File -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "Found $($searchFiles.Count) files to search for references" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
# Step 1: Update all references in files
|
||||
Write-Host "STEP 1: Updating references in files..." -ForegroundColor Green
|
||||
$totalReplacements = 0
|
||||
|
||||
foreach ($file in $searchFiles) {
|
||||
$content = Get-Content -Path $file.FullName -Raw -ErrorAction SilentlyContinue
|
||||
if (-not $content) { continue }
|
||||
|
||||
$originalContent = $content
|
||||
$fileChanged = $false
|
||||
|
||||
foreach ($oldName in $renames.Keys) {
|
||||
$newName = $renames[$oldName]
|
||||
if ($content -match [regex]::Escape($oldName)) {
|
||||
$content = $content -replace [regex]::Escape($oldName), $newName
|
||||
$fileChanged = $true
|
||||
$totalReplacements++
|
||||
}
|
||||
}
|
||||
|
||||
if ($fileChanged) {
|
||||
Write-Host " Updated: $($file.Name)" -ForegroundColor White
|
||||
if ($Execute) {
|
||||
Set-Content -Path $file.FullName -Value $content -NoNewline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host " Total replacements: $totalReplacements" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Step 2: Rename the files
|
||||
Write-Host "STEP 2: Renaming files..." -ForegroundColor Green
|
||||
$renamedCount = 0
|
||||
|
||||
foreach ($oldName in $renames.Keys) {
|
||||
$newName = $renames[$oldName]
|
||||
$oldPath = Join-Path $shopdbPath $oldName
|
||||
$newPath = Join-Path $shopdbPath $newName
|
||||
|
||||
if (Test-Path $oldPath) {
|
||||
Write-Host " $oldName -> $newName" -ForegroundColor White
|
||||
if ($Execute) {
|
||||
Rename-Item -Path $oldPath -NewName $newName
|
||||
}
|
||||
$renamedCount++
|
||||
} else {
|
||||
Write-Host " SKIP: $oldName (not found)" -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host " Files to rename: $renamedCount" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Step 3: Delete test files
|
||||
Write-Host "STEP 3: Deleting test/duplicate files..." -ForegroundColor Green
|
||||
$deletedCount = 0
|
||||
|
||||
foreach ($fileName in $deleteFiles) {
|
||||
$filePath = Join-Path $shopdbPath $fileName
|
||||
if (Test-Path $filePath) {
|
||||
Write-Host " DELETE: $fileName" -ForegroundColor Red
|
||||
if ($Execute) {
|
||||
Remove-Item -Path $filePath -Force
|
||||
}
|
||||
$deletedCount++
|
||||
} else {
|
||||
Write-Host " SKIP: $fileName (not found)" -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host " Files to delete: $deletedCount" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Summary
|
||||
Write-Host "SUMMARY" -ForegroundColor Cyan
|
||||
Write-Host "=======" -ForegroundColor Cyan
|
||||
Write-Host " References updated: $totalReplacements"
|
||||
Write-Host " Files renamed: $renamedCount"
|
||||
Write-Host " Files deleted: $deletedCount"
|
||||
Write-Host ""
|
||||
|
||||
if (-not $Execute) {
|
||||
Write-Host "This was a DRY RUN. Run with -Execute to apply changes." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "Changes applied successfully!" -ForegroundColor Green
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Renames ASP files to remove underscores and updates all internal references.
|
||||
#
|
||||
# Usage:
|
||||
# ./09_rename_asp_files.sh # Dry run - shows what would change
|
||||
# ./09_rename_asp_files.sh --execute # Actually performs the renames
|
||||
#
|
||||
|
||||
SHOPDB_PATH="/home/camp/projects/windows/shopdb"
|
||||
EXECUTE=false
|
||||
|
||||
if [ "$1" == "--execute" ]; then
|
||||
EXECUTE=true
|
||||
fi
|
||||
|
||||
echo "ASP File Rename Script"
|
||||
echo "======================"
|
||||
echo ""
|
||||
|
||||
if [ "$EXECUTE" != "true" ]; then
|
||||
echo "DRY RUN MODE - No changes will be made"
|
||||
echo "Run with --execute to apply changes"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Define rename mappings
|
||||
declare -A RENAMES=(
|
||||
# Direct handlers
|
||||
["addlink_direct.asp"]="addlinkdirect.asp"
|
||||
["addsubnetbackend_direct.asp"]="addsubnetbackenddirect.asp"
|
||||
["editapplication_direct.asp"]="editapplicationdirect.asp"
|
||||
["saveapplication_direct.asp"]="saveapplicationdirect.asp"
|
||||
["savedevice_direct.asp"]="savedevicedirect.asp"
|
||||
["savemachine_direct.asp"]="savemachinedirect.asp"
|
||||
["savemodel_direct.asp"]="savemodeldirect.asp"
|
||||
["save_network_device.asp"]="savenetworkdevice.asp"
|
||||
["savenotification_direct.asp"]="savenotificationdirect.asp"
|
||||
["saveprinter_direct.asp"]="saveprinterdirect.asp"
|
||||
["saveusb_direct.asp"]="saveusbdirect.asp"
|
||||
["savevendor_direct.asp"]="savevendordirect.asp"
|
||||
["updatedevice_direct.asp"]="updatedevicedirect.asp"
|
||||
["updatelink_direct.asp"]="updatelinkdirect.asp"
|
||||
["updatenotification_direct.asp"]="updatenotificationdirect.asp"
|
||||
["updatepc_direct.asp"]="updatepcdirect.asp"
|
||||
["updatesubnet_direct.asp"]="updatesubnetdirect.asp"
|
||||
|
||||
# USB files
|
||||
["checkin_usb.asp"]="checkinusb.asp"
|
||||
["checkout_usb.asp"]="checkoutusb.asp"
|
||||
["savecheckin_usb.asp"]="savecheckinusb.asp"
|
||||
["savecheckout_usb.asp"]="savecheckoutusb.asp"
|
||||
["usb_history.asp"]="usbhistory.asp"
|
||||
|
||||
# API files
|
||||
["api_businessunits.asp"]="apibusinessunits.asp"
|
||||
["api_printers.asp"]="apiprinters.asp"
|
||||
["api_shopfloor.asp"]="apishopfloor.asp"
|
||||
["api_usb.asp"]="apiusb.asp"
|
||||
|
||||
# Machine/map files
|
||||
["machine_edit.asp"]="machineedit.asp"
|
||||
["machine_map.asp"]="machinemap.asp"
|
||||
["machine_map_editor.asp"]="machinemapeditor.asp"
|
||||
["network_devices.asp"]="networkdevices.asp"
|
||||
["network_map.asp"]="networkmap.asp"
|
||||
["network_map_debug.asp"]="networkmapdebug.asp"
|
||||
|
||||
# Printer files
|
||||
["check_duplicate_printers.asp"]="checkduplicateprinters.asp"
|
||||
["check_printer_machines_count.asp"]="checkprintermachinescount.asp"
|
||||
["cleanup_duplicate_printers_execute.asp"]="cleanupduplicateprintersexecute.asp"
|
||||
["insert_all_printer_machines.asp"]="insertallprintermachines.asp"
|
||||
["install_printer.asp"]="installprinter.asp"
|
||||
["printer_installer_map.asp"]="printerinstallermap.asp"
|
||||
["printer_links_generator.asp"]="printerlinksgenerator.asp"
|
||||
["printer_lookup.asp"]="printerlookup.asp"
|
||||
|
||||
# Other files
|
||||
["admin_clear_cache.asp"]="adminclearcache.asp"
|
||||
["bulk_update_notification_types.asp"]="bulkupdatenotificationtypes.asp"
|
||||
["displaylocation_device.asp"]="displaylocationdevice.asp"
|
||||
["quickadd_application.asp"]="quickaddapplication.asp"
|
||||
["refresh_zabbix_cache.asp"]="refreshzabbixcache.asp"
|
||||
)
|
||||
|
||||
# Files to delete
|
||||
DELETE_FILES=(
|
||||
"editmacine.asp"
|
||||
"editmachine_test.asp"
|
||||
"test_asp.asp"
|
||||
"test_db.asp"
|
||||
"test_switch_query.asp"
|
||||
"test_with_includes.asp"
|
||||
)
|
||||
|
||||
# Step 1: Update all references in files
|
||||
echo "STEP 1: Updating references in files..."
|
||||
TOTAL_REPLACEMENTS=0
|
||||
|
||||
for OLD_NAME in "${!RENAMES[@]}"; do
|
||||
NEW_NAME="${RENAMES[$OLD_NAME]}"
|
||||
|
||||
# Find files containing the old name
|
||||
FILES_WITH_REF=$(grep -rl "$OLD_NAME" "$SHOPDB_PATH"/*.asp "$SHOPDB_PATH"/includes/*.asp "$SHOPDB_PATH"/js/*.js 2>/dev/null)
|
||||
|
||||
if [ -n "$FILES_WITH_REF" ]; then
|
||||
for FILE in $FILES_WITH_REF; do
|
||||
echo " Updating $OLD_NAME -> $NEW_NAME in $(basename $FILE)"
|
||||
if [ "$EXECUTE" == "true" ]; then
|
||||
sed -i "s/$OLD_NAME/$NEW_NAME/g" "$FILE"
|
||||
fi
|
||||
TOTAL_REPLACEMENTS=$((TOTAL_REPLACEMENTS + 1))
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
echo " Total file updates: $TOTAL_REPLACEMENTS"
|
||||
echo ""
|
||||
|
||||
# Step 2: Rename the files
|
||||
echo "STEP 2: Renaming files..."
|
||||
RENAMED_COUNT=0
|
||||
|
||||
for OLD_NAME in "${!RENAMES[@]}"; do
|
||||
NEW_NAME="${RENAMES[$OLD_NAME]}"
|
||||
OLD_PATH="$SHOPDB_PATH/$OLD_NAME"
|
||||
NEW_PATH="$SHOPDB_PATH/$NEW_NAME"
|
||||
|
||||
if [ -f "$OLD_PATH" ]; then
|
||||
echo " $OLD_NAME -> $NEW_NAME"
|
||||
if [ "$EXECUTE" == "true" ]; then
|
||||
mv "$OLD_PATH" "$NEW_PATH"
|
||||
fi
|
||||
RENAMED_COUNT=$((RENAMED_COUNT + 1))
|
||||
else
|
||||
echo " SKIP: $OLD_NAME (not found)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo " Files to rename: $RENAMED_COUNT"
|
||||
echo ""
|
||||
|
||||
# Step 3: Delete test files
|
||||
echo "STEP 3: Deleting test/duplicate files..."
|
||||
DELETED_COUNT=0
|
||||
|
||||
for FILE_NAME in "${DELETE_FILES[@]}"; do
|
||||
FILE_PATH="$SHOPDB_PATH/$FILE_NAME"
|
||||
|
||||
if [ -f "$FILE_PATH" ]; then
|
||||
echo " DELETE: $FILE_NAME"
|
||||
if [ "$EXECUTE" == "true" ]; then
|
||||
rm -f "$FILE_PATH"
|
||||
fi
|
||||
DELETED_COUNT=$((DELETED_COUNT + 1))
|
||||
else
|
||||
echo " SKIP: $FILE_NAME (not found)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo " Files to delete: $DELETED_COUNT"
|
||||
echo ""
|
||||
|
||||
# Summary
|
||||
echo "SUMMARY"
|
||||
echo "======="
|
||||
echo " Files updated: $TOTAL_REPLACEMENTS"
|
||||
echo " Files renamed: $RENAMED_COUNT"
|
||||
echo " Files deleted: $DELETED_COUNT"
|
||||
echo ""
|
||||
|
||||
if [ "$EXECUTE" != "true" ]; then
|
||||
echo "This was a DRY RUN. Run with --execute to apply changes."
|
||||
else
|
||||
echo "Changes applied successfully!"
|
||||
fi
|
||||
@@ -1,261 +0,0 @@
|
||||
# Database Naming Convention Fix - Production Deployment Guide
|
||||
|
||||
## Overview
|
||||
|
||||
This guide covers migrating table names from `snake_case` to `camelCase` to match the existing naming convention in ShopDB.
|
||||
|
||||
**Target Environment:**
|
||||
- Production Server: Windows with IIS
|
||||
- Database: MySQL 5.6
|
||||
|
||||
**Tables being renamed:**
|
||||
| Old Name | New Name |
|
||||
|----------|----------|
|
||||
| `machine_overrides` | `machineoverrides` |
|
||||
| `pc_comm_config` | `commconfig` |
|
||||
| `pc_dnc_config` | `dncconfig` |
|
||||
| `pc_dualpath_assignments` | `dualpathassignments` |
|
||||
| `pc_network_interfaces` | `networkinterfaces` |
|
||||
| `usb_checkouts` | `usbcheckouts` |
|
||||
|
||||
**Tables being dropped (migration backups):**
|
||||
- `_backup_equipment_ips_phase1_5`
|
||||
- `pc_backup_phase2`
|
||||
|
||||
**Note:** `pc_to_machine_id_mapping` is kept for now as views depend on it for pcid->machineid mapping.
|
||||
|
||||
---
|
||||
|
||||
## Pre-Deployment Checklist
|
||||
|
||||
- [ ] Full database backup completed
|
||||
- [ ] IIS can be stopped briefly (coordinate with users)
|
||||
- [ ] All scripts tested on dev environment
|
||||
- [ ] ASP file changes committed to git and ready to deploy
|
||||
- [ ] Rollback plan ready
|
||||
|
||||
---
|
||||
|
||||
## Deployment Steps
|
||||
|
||||
### Phase 1: Preparation (No Downtime)
|
||||
|
||||
1. **Backup production database (Windows)**
|
||||
```cmd
|
||||
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" -u root -p shopdb > C:\backups\shopdb_backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%.sql
|
||||
```
|
||||
|
||||
Or using MySQL Workbench:
|
||||
- Server > Data Export
|
||||
- Select `shopdb` database
|
||||
- Export to Self-Contained File
|
||||
|
||||
2. **Prepare ASP files for deployment**
|
||||
- Pull latest from Gitea with updated table names
|
||||
- Or have files ready to copy
|
||||
|
||||
### Phase 2: Database Migration (Brief Downtime ~2-5 min)
|
||||
|
||||
1. **Stop IIS** (Administrator Command Prompt)
|
||||
```cmd
|
||||
iisreset /stop
|
||||
```
|
||||
|
||||
2. **Connect to production MySQL 5.6**
|
||||
```cmd
|
||||
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -u root -p shopdb
|
||||
```
|
||||
|
||||
Or use MySQL Workbench to connect.
|
||||
|
||||
3. **Drop dependent views**
|
||||
```sql
|
||||
DROP VIEW IF EXISTS vw_active_pcs;
|
||||
DROP VIEW IF EXISTS vw_dnc_config;
|
||||
DROP VIEW IF EXISTS vw_engineer_pcs;
|
||||
DROP VIEW IF EXISTS vw_pc_network_summary;
|
||||
DROP VIEW IF EXISTS vw_pc_resolved_machines;
|
||||
DROP VIEW IF EXISTS vw_pcs_by_hardware;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_comm_config;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_pcs;
|
||||
DROP VIEW IF EXISTS vw_standard_pcs;
|
||||
```
|
||||
|
||||
4. **Rename tables**
|
||||
```sql
|
||||
RENAME TABLE machine_overrides TO machineoverrides;
|
||||
RENAME TABLE pc_comm_config TO commconfig;
|
||||
RENAME TABLE pc_dnc_config TO dncconfig;
|
||||
RENAME TABLE pc_dualpath_assignments TO dualpathassignments;
|
||||
RENAME TABLE pc_network_interfaces TO networkinterfaces;
|
||||
RENAME TABLE usb_checkouts TO usbcheckouts;
|
||||
```
|
||||
|
||||
5. **Recreate views**
|
||||
- Open `04_drop_and_recreate_views.sql` in MySQL Workbench
|
||||
- Skip the DROP statements (already done in step 3)
|
||||
- Run all the CREATE VIEW statements
|
||||
- Or run the entire script (DROPs will just say "view doesn't exist")
|
||||
|
||||
6. **Verify tables renamed**
|
||||
```sql
|
||||
SHOW TABLES LIKE '%config%';
|
||||
SHOW TABLES LIKE '%override%';
|
||||
SHOW TABLES LIKE '%checkout%';
|
||||
```
|
||||
|
||||
7. **Verify views working**
|
||||
```sql
|
||||
SELECT COUNT(*) FROM vw_shopfloor_pcs;
|
||||
SELECT COUNT(*) FROM vw_active_pcs;
|
||||
```
|
||||
|
||||
8. **Update ASP files using PowerShell script**
|
||||
```powershell
|
||||
cd C:\path\to\shopdb
|
||||
.\sql\naming_convention_fix\05_update_asp_files.ps1 # Dry run - shows changes
|
||||
.\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute # Apply changes
|
||||
```
|
||||
Or manually copy pre-updated ASP files from git
|
||||
|
||||
9. **Start IIS**
|
||||
```cmd
|
||||
iisreset /start
|
||||
```
|
||||
|
||||
10. **Test key pages in browser:**
|
||||
- http://yourserver/displaypcs.asp
|
||||
- http://yourserver/displayusb.asp
|
||||
- http://yourserver/api.asp (test endpoint)
|
||||
|
||||
### Phase 3: Cleanup (Optional, No Downtime)
|
||||
|
||||
1. **Drop migration backup tables** (only after confirming everything works)
|
||||
```sql
|
||||
DROP TABLE IF EXISTS _backup_equipment_ips_phase1_5;
|
||||
DROP TABLE IF EXISTS pc_backup_phase2;
|
||||
```
|
||||
|
||||
2. **Update documentation** (low priority, can do anytime)
|
||||
```powershell
|
||||
.\sql\naming_convention_fix\06_update_docs.ps1 # Dry run
|
||||
.\sql\naming_convention_fix\06_update_docs.ps1 -Execute # Apply changes
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Rollback Plan
|
||||
|
||||
If issues occur, restore from backup:
|
||||
|
||||
**Windows Command Prompt (as Administrator):**
|
||||
```cmd
|
||||
REM Stop IIS
|
||||
iisreset /stop
|
||||
|
||||
REM Restore database
|
||||
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -u root -p shopdb < C:\backups\shopdb_backup_YYYYMMDD.sql
|
||||
|
||||
REM Restore original ASP files from git or backup
|
||||
cd C:\inetpub\wwwroot\shopdb
|
||||
git checkout HEAD~1 -- *.asp
|
||||
|
||||
REM Start IIS
|
||||
iisreset /start
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files Changed
|
||||
|
||||
### ASP Files (9 files)
|
||||
| File | Tables Referenced |
|
||||
|------|-------------------|
|
||||
| api.asp | commconfig, dncconfig |
|
||||
| displaypc.asp | networkinterfaces |
|
||||
| displaysubnet.asp | networkinterfaces |
|
||||
| displaymachine.asp | networkinterfaces |
|
||||
| usb_history.asp | usbcheckouts |
|
||||
| savecheckin_usb.asp | usbcheckouts |
|
||||
| displayprofile.asp | usbcheckouts |
|
||||
| displayusb.asp | usbcheckouts |
|
||||
| savecheckout_usb.asp | usbcheckouts |
|
||||
| api_usb.asp | usbcheckouts |
|
||||
|
||||
### Views Recreated (9 views)
|
||||
- vw_active_pcs
|
||||
- vw_dnc_config
|
||||
- vw_engineer_pcs
|
||||
- vw_pc_network_summary
|
||||
- vw_pc_resolved_machines
|
||||
- vw_pcs_by_hardware
|
||||
- vw_shopfloor_comm_config
|
||||
- vw_shopfloor_pcs (references machineoverrides)
|
||||
- vw_standard_pcs
|
||||
|
||||
---
|
||||
|
||||
## Production Commands Quick Reference
|
||||
|
||||
Copy and paste these into MySQL Workbench or mysql command line:
|
||||
|
||||
```sql
|
||||
-- =============================================
|
||||
-- STEP 1: Drop views
|
||||
-- =============================================
|
||||
DROP VIEW IF EXISTS vw_active_pcs;
|
||||
DROP VIEW IF EXISTS vw_dnc_config;
|
||||
DROP VIEW IF EXISTS vw_engineer_pcs;
|
||||
DROP VIEW IF EXISTS vw_pc_network_summary;
|
||||
DROP VIEW IF EXISTS vw_pc_resolved_machines;
|
||||
DROP VIEW IF EXISTS vw_pcs_by_hardware;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_comm_config;
|
||||
DROP VIEW IF EXISTS vw_shopfloor_pcs;
|
||||
DROP VIEW IF EXISTS vw_standard_pcs;
|
||||
|
||||
-- =============================================
|
||||
-- STEP 2: Rename tables
|
||||
-- =============================================
|
||||
RENAME TABLE machine_overrides TO machineoverrides;
|
||||
RENAME TABLE pc_comm_config TO commconfig;
|
||||
RENAME TABLE pc_dnc_config TO dncconfig;
|
||||
RENAME TABLE pc_dualpath_assignments TO dualpathassignments;
|
||||
RENAME TABLE pc_network_interfaces TO networkinterfaces;
|
||||
RENAME TABLE usb_checkouts TO usbcheckouts;
|
||||
|
||||
-- =============================================
|
||||
-- STEP 3: Recreate views
|
||||
-- Copy from 04_drop_and_recreate_views.sql Part 2
|
||||
-- =============================================
|
||||
|
||||
-- =============================================
|
||||
-- STEP 4: Verify
|
||||
-- =============================================
|
||||
SHOW TABLES;
|
||||
SELECT COUNT(*) FROM vw_shopfloor_pcs;
|
||||
SELECT COUNT(*) FROM vw_active_pcs;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Windows IIS Commands Reference
|
||||
|
||||
```cmd
|
||||
REM Stop IIS completely
|
||||
iisreset /stop
|
||||
|
||||
REM Start IIS
|
||||
iisreset /start
|
||||
|
||||
REM Restart IIS (stop then start)
|
||||
iisreset /restart
|
||||
|
||||
REM Check IIS status
|
||||
iisreset /status
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Gitea Issue
|
||||
|
||||
Track progress at: http://localhost:3000/cproudlock/shopdb/issues/1
|
||||
@@ -1,56 +0,0 @@
|
||||
-- =============================================================================
|
||||
-- Migration: Remove Legacy IP/Network Columns from machines Table
|
||||
-- Date: 2025-11-14
|
||||
-- Purpose: Remove unused network columns from machines table
|
||||
-- All network data now stored in communications table
|
||||
-- =============================================================================
|
||||
|
||||
-- PREREQUISITE: Printer IP addresses migrated to communications table
|
||||
-- Run: migrate_printer_ips_to_communications.sql first
|
||||
|
||||
-- STEP 1: Drop legacy IP address columns
|
||||
-- Note: ipaddress1 was used by printers (now in communications)
|
||||
-- ipaddress2, ipaddress3 were never used (0 records)
|
||||
|
||||
ALTER TABLE machines DROP COLUMN ipaddress1;
|
||||
ALTER TABLE machines DROP COLUMN ipaddress2;
|
||||
ALTER TABLE machines DROP COLUMN ipaddress3;
|
||||
|
||||
-- STEP 2: Drop legacy MAC address columns
|
||||
-- Note: macaddress1/2/3 were never used (0 records, no ASP references)
|
||||
|
||||
ALTER TABLE machines DROP COLUMN macaddress1;
|
||||
ALTER TABLE machines DROP COLUMN macaddress2;
|
||||
ALTER TABLE machines DROP COLUMN macaddress3;
|
||||
|
||||
-- STEP 3: Drop VLAN column
|
||||
-- Note: Used in subnet management but never populated in machines table
|
||||
|
||||
ALTER TABLE machines DROP COLUMN vlan;
|
||||
|
||||
-- =============================================================================
|
||||
-- Verification Queries
|
||||
-- =============================================================================
|
||||
|
||||
-- Check machines table columns count
|
||||
-- SELECT COUNT(*) as machines_columns
|
||||
-- FROM information_schema.COLUMNS
|
||||
-- WHERE TABLE_SCHEMA='shopdb' AND TABLE_NAME='machines';
|
||||
|
||||
-- Verify no IP columns remain
|
||||
-- SELECT COLUMN_NAME
|
||||
-- FROM information_schema.COLUMNS
|
||||
-- WHERE TABLE_SCHEMA='shopdb' AND TABLE_NAME='machines'
|
||||
-- AND COLUMN_NAME LIKE '%ipaddress%' OR COLUMN_NAME LIKE '%macaddress%' OR COLUMN_NAME = 'vlan';
|
||||
|
||||
-- Verify printer IPs are in communications table
|
||||
-- SELECT COUNT(*) as printer_comms
|
||||
-- FROM communications c
|
||||
-- INNER JOIN machines m ON c.machineid = m.machineid
|
||||
-- WHERE m.machinetypeid = 15 AND c.comstypeid = 1;
|
||||
|
||||
-- =============================================================================
|
||||
-- Status: Ready to execute
|
||||
-- Impact: Removes 7 unused/migrated columns from machines table
|
||||
-- Tested: Pages updated to use communications table
|
||||
-- =============================================================================
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user