Execute naming convention fix on dev - tables renamed, ASP updated

Database changes applied:
- machine_overrides -> machineoverrides
- pc_comm_config -> commconfig
- pc_dnc_config -> dncconfig
- pc_dualpath_assignments -> dualpathassignments
- pc_network_interfaces -> networkinterfaces
- usb_checkouts -> usbcheckouts

ASP files updated (10 files):
- api.asp, api_usb.asp
- displaypc.asp, displaysubnet.asp, displaymachine.asp
- displayusb.asp, displayprofile.asp
- usb_history.asp, savecheckin_usb.asp, savecheckout_usb.asp

9 views recreated with new table references.

Tested and verified working on dev environment.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-10 14:59:47 -05:00
parent 946074148f
commit 30ea1bb42f
12 changed files with 46 additions and 41 deletions

12
api.asp
View File

@@ -1256,19 +1256,19 @@ Sub ClearShopfloorData(hostname)
LogToFile "Deleted " & cmdDelete.RecordsAffected & " communications records" LogToFile "Deleted " & cmdDelete.RecordsAffected & " communications records"
' Delete from pc_comm_config ' Delete from commconfig
Set cmdDelete = Server.CreateObject("ADODB.Command") Set cmdDelete = Server.CreateObject("ADODB.Command")
cmdDelete.ActiveConnection = objConn cmdDelete.ActiveConnection = objConn
cmdDelete.CommandText = "DELETE FROM pc_comm_config WHERE machineid = ?" cmdDelete.CommandText = "DELETE FROM commconfig WHERE machineid = ?"
cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid)) cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid))
cmdDelete.Execute cmdDelete.Execute
LogToFile "Deleted " & cmdDelete.RecordsAffected & " comm config records" LogToFile "Deleted " & cmdDelete.RecordsAffected & " comm config records"
' Delete from pc_dnc_config ' Delete from dncconfig
Set cmdDelete = Server.CreateObject("ADODB.Command") Set cmdDelete = Server.CreateObject("ADODB.Command")
cmdDelete.ActiveConnection = objConn cmdDelete.ActiveConnection = objConn
cmdDelete.CommandText = "DELETE FROM pc_dnc_config WHERE machineid = ?" cmdDelete.CommandText = "DELETE FROM dncconfig WHERE machineid = ?"
cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid)) cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid))
cmdDelete.Execute cmdDelete.Execute
@@ -1372,7 +1372,7 @@ Function InsertCommConfigs(machineid, commConfigsJSON)
Dim cmdInsert Dim cmdInsert
Set cmdInsert = Server.CreateObject("ADODB.Command") Set cmdInsert = Server.CreateObject("ADODB.Command")
cmdInsert.ActiveConnection = objConn cmdInsert.ActiveConnection = objConn
cmdInsert.CommandText = "INSERT INTO pc_comm_config (" & _ cmdInsert.CommandText = "INSERT INTO commconfig (" & _
"machineid, portname, baudrate, databits, parity, stopbits, flowcontrol" & _ "machineid, portname, baudrate, databits, parity, stopbits, flowcontrol" & _
") VALUES (?, ?, ?, ?, ?, ?, ?)" ") VALUES (?, ?, ?, ?, ?, ?, ?)"
@@ -1447,7 +1447,7 @@ Function InsertDNCConfig(machineid, dncConfigJSON, dualPathEnabled, path1Name, p
Dim cmdInsert Dim cmdInsert
Set cmdInsert = Server.CreateObject("ADODB.Command") Set cmdInsert = Server.CreateObject("ADODB.Command")
cmdInsert.ActiveConnection = objConn cmdInsert.ActiveConnection = objConn
cmdInsert.CommandText = "INSERT INTO pc_dnc_config (" & _ cmdInsert.CommandText = "INSERT INTO dncconfig (" & _
"machineid, site, cnc, ncif, machinenumber, hosttype, " & _ "machineid, site, cnc, ncif, machinenumber, hosttype, " & _
"ftphostprimary, ftphostsecondary, ftpaccount, " & _ "ftphostprimary, ftphostsecondary, ftpaccount, " & _
"debug, uploads, scanner, dripfeed, additionalsettings, " & _ "debug, uploads, scanner, dripfeed, additionalsettings, " & _

View File

@@ -62,10 +62,10 @@ Sub LookupUSB()
' Look up USB device ' Look up USB device
strSQL = "SELECT m.machineid, m.serialnumber, m.alias, bu.businessunit, " & _ strSQL = "SELECT m.machineid, m.serialnumber, m.alias, bu.businessunit, " & _
"uc.checkoutid, uc.sso AS current_holder, uc.checkout_time, " & _ "uc.checkoutid, uc.sso AS current_holder, uc.checkout_time, " & _
"(SELECT MAX(uc2.checkout_time) FROM usb_checkouts uc2 WHERE uc2.machineid = m.machineid) AS last_checkout " & _ "(SELECT MAX(uc2.checkout_time) FROM usbcheckouts uc2 WHERE uc2.machineid = m.machineid) AS last_checkout " & _
"FROM machines m " & _ "FROM machines m " & _
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _ "LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _
"LEFT JOIN usb_checkouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _ "LEFT JOIN usbcheckouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _
"WHERE m.machinetypeid = 44 AND m.isactive = 1 AND m.serialnumber = ?" "WHERE m.machinetypeid = 44 AND m.isactive = 1 AND m.serialnumber = ?"
Set cmd = Server.CreateObject("ADODB.Command") Set cmd = Server.CreateObject("ADODB.Command")
@@ -156,7 +156,7 @@ Sub CheckinLookup()
"uc.checkoutid, uc.sso, uc.checkout_time, uc.checkout_reason " & _ "uc.checkoutid, uc.sso, uc.checkout_time, uc.checkout_reason " & _
"FROM machines m " & _ "FROM machines m " & _
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _ "LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _
"INNER JOIN usb_checkouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _ "INNER JOIN usbcheckouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _
"WHERE m.machinetypeid = 44 AND m.isactive = 1 AND m.serialnumber = ?" "WHERE m.machinetypeid = 44 AND m.isactive = 1 AND m.serialnumber = ?"
Set cmd = Server.CreateObject("ADODB.Command") Set cmd = Server.CreateObject("ADODB.Command")

View File

@@ -73,7 +73,7 @@
'============================================================================= '=============================================================================
' SECURITY: Use parameterized query to prevent SQL injection ' SECURITY: Use parameterized query to prevent SQL injection
' PHASE 2: Removed pc and pc_network_interfaces tables (migrated to machines) ' PHASE 2: Removed pc and networkinterfaces tables (migrated to machines)
' NOTE: Use explicit column names to avoid wildcard conflicts between tables ' NOTE: Use explicit column names to avoid wildcard conflicts between tables
'============================================================================= '=============================================================================
' Phase 2: Only query columns that actually exist in machines table ' Phase 2: Only query columns that actually exist in machines table

View File

@@ -75,7 +75,7 @@
'============================================================================= '=============================================================================
' SECURITY: Use parameterized query to prevent SQL injection ' SECURITY: Use parameterized query to prevent SQL injection
' PHASE 2: Removed pc and pc_network_interfaces tables (migrated to machines) ' PHASE 2: Removed pc and networkinterfaces tables (migrated to machines)
' NOTE: Use explicit column names to avoid wildcard conflicts between tables ' NOTE: Use explicit column names to avoid wildcard conflicts between tables
'============================================================================= '=============================================================================
' Phase 2: Only query columns that actually exist in machines table ' Phase 2: Only query columns that actually exist in machines table

View File

@@ -282,7 +282,7 @@ If shopdbAvailable And IsNumeric(sso) Then
"COUNT(*) AS total_checkouts, " & _ "COUNT(*) AS total_checkouts, " & _
"SUM(CASE WHEN checkin_time IS NULL THEN 1 ELSE 0 END) AS active_checkouts, " & _ "SUM(CASE WHEN checkin_time IS NULL THEN 1 ELSE 0 END) AS active_checkouts, " & _
"AVG(TIMESTAMPDIFF(MINUTE, checkout_time, COALESCE(checkin_time, NOW()))) AS avg_duration " & _ "AVG(TIMESTAMPDIFF(MINUTE, checkout_time, COALESCE(checkin_time, NOW()))) AS avg_duration " & _
"FROM usb_checkouts WHERE sso = ?" "FROM usbcheckouts WHERE sso = ?"
Set cmdStats = Server.CreateObject("ADODB.Command") Set cmdStats = Server.CreateObject("ADODB.Command")
cmdStats.ActiveConnection = objConnShopdb cmdStats.ActiveConnection = objConnShopdb
@@ -379,7 +379,7 @@ If shopdbAvailable And IsNumeric(sso) Then
Dim historySQL Dim historySQL
historySQL = "SELECT uc.*, m.serialnumber, m.alias, " & _ historySQL = "SELECT uc.*, m.serialnumber, m.alias, " & _
"TIMESTAMPDIFF(MINUTE, uc.checkout_time, COALESCE(uc.checkin_time, NOW())) AS duration_minutes " & _ "TIMESTAMPDIFF(MINUTE, uc.checkout_time, COALESCE(uc.checkin_time, NOW())) AS duration_minutes " & _
"FROM usb_checkouts uc " & _ "FROM usbcheckouts uc " & _
"JOIN machines m ON uc.machineid = m.machineid " & _ "JOIN machines m ON uc.machineid = m.machineid " & _
"WHERE uc.sso = ? " & _ "WHERE uc.sso = ? " & _
"ORDER BY uc.checkout_time DESC" "ORDER BY uc.checkout_time DESC"

View File

@@ -26,7 +26,7 @@
END IF END IF
'-------------------------------------------------------Is this the IP address of a PC--------------------------------------------------- '-------------------------------------------------------Is this the IP address of a PC---------------------------------------------------
IF search <> "" THEN IF search <> "" THEN
' PHASE 2: Query communications table instead of pc_network_interfaces ' PHASE 2: Query communications table instead of networkinterfaces
strSQL = "SELECT c.machineid FROM communications c JOIN machines m ON c.machineid = m.machineid WHERE c.address='" &search &"' AND m.pctypeid IS NOT NULL LIMIT 1" strSQL = "SELECT c.machineid FROM communications c JOIN machines m ON c.machineid = m.machineid WHERE c.address='" &search &"' AND m.pctypeid IS NOT NULL LIMIT 1"
set rs = objconn.Execute(strSQL) set rs = objconn.Execute(strSQL)
IF NOT rs.EOF THEN IF NOT rs.EOF THEN

View File

@@ -101,7 +101,7 @@
"CASE WHEN uc.checkoutid IS NOT NULL THEN 'Checked Out' ELSE 'Available' END AS status " & _ "CASE WHEN uc.checkoutid IS NOT NULL THEN 'Checked Out' ELSE 'Available' END AS status " & _
"FROM machines m " & _ "FROM machines m " & _
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _ "LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _
"LEFT JOIN usb_checkouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _ "LEFT JOIN usbcheckouts uc ON m.machineid = uc.machineid AND uc.checkin_time IS NULL " & _
"WHERE m.machinetypeid = 44 AND m.isactive = 1 " "WHERE m.machinetypeid = 44 AND m.isactive = 1 "
' Apply filter ' Apply filter

View File

@@ -35,7 +35,7 @@
' Verify the checkout record exists and is still open ' Verify the checkout record exists and is still open
Dim checkSQL, cmdCheck, rsCheck Dim checkSQL, cmdCheck, rsCheck
checkSQL = "SELECT uc.checkoutid, uc.machineid, uc.sso, m.serialnumber, m.alias " & _ checkSQL = "SELECT uc.checkoutid, uc.machineid, uc.sso, m.serialnumber, m.alias " & _
"FROM usb_checkouts uc " & _ "FROM usbcheckouts uc " & _
"JOIN machines m ON uc.machineid = m.machineid " & _ "JOIN machines m ON uc.machineid = m.machineid " & _
"WHERE uc.checkoutid = ? AND uc.checkin_time IS NULL" "WHERE uc.checkoutid = ? AND uc.checkin_time IS NULL"
@@ -67,7 +67,7 @@
' Update checkout record with check-in info ' Update checkout record with check-in info
Dim updateSQL, cmdUpdate Dim updateSQL, cmdUpdate
updateSQL = "UPDATE usb_checkouts SET checkin_time = NOW(), was_wiped = ?, checkin_notes = ? WHERE checkoutid = ?" updateSQL = "UPDATE usbcheckouts SET checkin_time = NOW(), was_wiped = ?, checkin_notes = ? WHERE checkoutid = ?"
Set cmdUpdate = Server.CreateObject("ADODB.Command") Set cmdUpdate = Server.CreateObject("ADODB.Command")
cmdUpdate.ActiveConnection = objConn cmdUpdate.ActiveConnection = objConn

View File

@@ -43,7 +43,7 @@
' Verify the USB device exists and is available ' Verify the USB device exists and is available
Dim checkSQL, cmdCheck, rsCheck Dim checkSQL, cmdCheck, rsCheck
checkSQL = "SELECT m.machineid, m.serialnumber, m.alias, " & _ checkSQL = "SELECT m.machineid, m.serialnumber, m.alias, " & _
"(SELECT COUNT(*) FROM usb_checkouts uc WHERE uc.machineid = m.machineid AND uc.checkin_time IS NULL) AS is_checked_out " & _ "(SELECT COUNT(*) FROM usbcheckouts uc WHERE uc.machineid = m.machineid AND uc.checkin_time IS NULL) AS is_checked_out " & _
"FROM machines m " & _ "FROM machines m " & _
"WHERE m.machineid = ? AND m.machinetypeid = 44 AND m.isactive = 1" "WHERE m.machineid = ? AND m.machinetypeid = 44 AND m.isactive = 1"
@@ -85,7 +85,7 @@
' Insert checkout record ' Insert checkout record
Dim insertSQL, cmdInsert Dim insertSQL, cmdInsert
insertSQL = "INSERT INTO usb_checkouts (machineid, sso, checkout_reason, checkout_time) VALUES (?, ?, ?, NOW())" insertSQL = "INSERT INTO usbcheckouts (machineid, sso, checkout_reason, checkout_time) VALUES (?, ?, ?, NOW())"
Set cmdInsert = Server.CreateObject("ADODB.Command") Set cmdInsert = Server.CreateObject("ADODB.Command")
cmdInsert.ActiveConnection = objConn cmdInsert.ActiveConnection = objConn

View File

@@ -3,14 +3,22 @@
-- Purpose: Drop views that reference underscore tables, recreate with new names -- Purpose: Drop views that reference underscore tables, recreate with new names
-- Target: MySQL 5.6 (dev and production) -- Target: MySQL 5.6 (dev and production)
-- --
-- USAGE: -- IMPORTANT: This is a SINGLE script. Run it all at once in MySQL Workbench
-- 1. Run Part 1 (DROP) BEFORE running 03_rename_tables.sql -- 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 -- 2. Run 03_rename_tables.sql
-- 3. Run Part 2 (CREATE) AFTER running 03_rename_tables.sql -- 3. Run just the CREATE statements
-- ============================================================================ -- ============================================================================
-- ============================================================================ -- ============================================================================
-- PART 1: DROP VIEWS (run BEFORE table renames) -- PART 1: DROP VIEWS
-- ============================================================================ -- ============================================================================
DROP VIEW IF EXISTS vw_active_pcs; DROP VIEW IF EXISTS vw_active_pcs;
@@ -23,12 +31,10 @@ DROP VIEW IF EXISTS vw_shopfloor_comm_config;
DROP VIEW IF EXISTS vw_shopfloor_pcs; DROP VIEW IF EXISTS vw_shopfloor_pcs;
DROP VIEW IF EXISTS vw_standard_pcs; DROP VIEW IF EXISTS vw_standard_pcs;
SELECT 'Views dropped. Now run 03_rename_tables.sql, then run Part 2 below.' AS status;
-- ============================================================================ -- ============================================================================
-- PART 2: RECREATE VIEWS (run AFTER table renames) -- PART 2: RECREATE VIEWS
-- Note: These views now reference machineoverrides instead of machine_overrides -- Note: These reference the NEW table name: machineoverrides (not machine_overrides)
-- Note: pc_to_machine_id_mapping is kept for now as it's used for pcid mapping -- Note: pc_to_machine_id_mapping is kept for pcid->machineid mapping
-- ============================================================================ -- ============================================================================
-- vw_active_pcs -- vw_active_pcs
@@ -241,10 +247,8 @@ ORDER BY m.hostname;
-- VERIFICATION -- VERIFICATION
-- ============================================================================ -- ============================================================================
SELECT 'Verifying views recreated...' AS status; SELECT 'Views recreated successfully!' AS status;
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
SELECT TABLE_NAME, VIEW_DEFINITION IS NOT NULL AS has_definition
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = DATABASE() WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME IN ( AND TABLE_NAME IN (
'vw_active_pcs', 'vw_active_pcs',
@@ -256,6 +260,5 @@ AND TABLE_NAME IN (
'vw_shopfloor_comm_config', 'vw_shopfloor_comm_config',
'vw_shopfloor_pcs', 'vw_shopfloor_pcs',
'vw_standard_pcs' 'vw_standard_pcs'
); )
ORDER BY TABLE_NAME;
SELECT 'Views recreated successfully!' AS status;

View File

@@ -68,7 +68,7 @@ This guide covers migrating table names from `snake_case` to `camelCase` to matc
Or use MySQL Workbench to connect. Or use MySQL Workbench to connect.
3. **Drop dependent views (Part 1 of script 04)** 3. **Drop dependent views**
```sql ```sql
DROP VIEW IF EXISTS vw_active_pcs; DROP VIEW IF EXISTS vw_active_pcs;
DROP VIEW IF EXISTS vw_dnc_config; DROP VIEW IF EXISTS vw_dnc_config;
@@ -81,7 +81,7 @@ This guide covers migrating table names from `snake_case` to `camelCase` to matc
DROP VIEW IF EXISTS vw_standard_pcs; DROP VIEW IF EXISTS vw_standard_pcs;
``` ```
4. **Rename tables (script 03)** 4. **Rename tables**
```sql ```sql
RENAME TABLE machine_overrides TO machineoverrides; RENAME TABLE machine_overrides TO machineoverrides;
RENAME TABLE pc_comm_config TO commconfig; RENAME TABLE pc_comm_config TO commconfig;
@@ -91,9 +91,11 @@ This guide covers migrating table names from `snake_case` to `camelCase` to matc
RENAME TABLE usb_checkouts TO usbcheckouts; RENAME TABLE usb_checkouts TO usbcheckouts;
``` ```
5. **Recreate views (Part 2 of script 04)** 5. **Recreate views**
- Run the CREATE VIEW statements from `04_drop_and_recreate_views.sql` - Open `04_drop_and_recreate_views.sql` in MySQL Workbench
- Can copy/paste into MySQL Workbench or run as script - 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** 6. **Verify tables renamed**
```sql ```sql

View File

@@ -82,7 +82,7 @@
' Build query with optional filters ' Build query with optional filters
strSQL = "SELECT uc.*, m.serialnumber, m.alias, " & _ strSQL = "SELECT uc.*, m.serialnumber, m.alias, " & _
"TIMESTAMPDIFF(MINUTE, uc.checkout_time, COALESCE(uc.checkin_time, NOW())) AS duration_minutes " & _ "TIMESTAMPDIFF(MINUTE, uc.checkout_time, COALESCE(uc.checkin_time, NOW())) AS duration_minutes " & _
"FROM usb_checkouts uc " & _ "FROM usbcheckouts uc " & _
"JOIN machines m ON uc.machineid = m.machineid " & _ "JOIN machines m ON uc.machineid = m.machineid " & _
"WHERE 1=1 " "WHERE 1=1 "