Add database view consolidation and migrate legacy tables
- Drop 27 unused views, create 24 new purpose-built views - New views cover: equipment, PCs, printers, notifications, applications, knowledge base, USB history, subnets, maps, and reports/charts - Migration scripts for legacy network device tables (servers, cameras, switches, accesspoints, idfs) to unified machines table - Migration scripts for legacy tables (machineoverrides, dualpathassignments, networkinterfaces) - Update displaydevice.asp and displaylocationdevice.asp to use machines table - Fix deviceserver.asp type mismatch error with HTMLEncode - Hide Applications tab for equipment in displaymachine.asp 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,61 +26,77 @@
|
||||
End If
|
||||
|
||||
' Build query based on device type
|
||||
Dim strSQL, rs, tableName, idField, editUrl, listUrl
|
||||
' All network devices now use unified machines table with machinetypeid:
|
||||
' 16 = Access Point, 17 = Camera, 18 = IDF, 19 = Switch, 20 = Server
|
||||
Dim strSQL, rs, tableName, idField, editUrl, listUrl, machineTypeId
|
||||
Select Case LCase(deviceType)
|
||||
Case "idf"
|
||||
tableName = "idfs"
|
||||
idField = "idfid"
|
||||
machineTypeId = 18
|
||||
editUrl = "deviceidf.asp?id=" & deviceId
|
||||
listUrl = "networkdevices.asp?filter=IDF"
|
||||
strSQL = "SELECT i.idfid, i.idfname, i.description, i.maptop, i.mapleft, i.isactive, " & _
|
||||
"NULL AS vendor, NULL AS modelnumber, NULL AS serialnumber, NULL AS ipaddress, NULL AS macaddress, 'IDF' AS devicetype " & _
|
||||
"FROM idfs i WHERE i.idfid = " & CLng(deviceId)
|
||||
strSQL = "SELECT mac.machineid, COALESCE(mac.alias, mac.machinenumber) AS idfname, " & _
|
||||
"mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _
|
||||
"NULL AS vendor, NULL AS modelnumber, NULL AS serialnumber, NULL AS ipaddress, NULL AS macaddress, " & _
|
||||
"'IDF' AS devicetype " & _
|
||||
"FROM machines mac " & _
|
||||
"WHERE mac.machineid = " & CLng(deviceId) & " AND mac.machinetypeid = 18"
|
||||
Case "server"
|
||||
tableName = "servers"
|
||||
idField = "serverid"
|
||||
machineTypeId = 20
|
||||
editUrl = "deviceserver.asp?id=" & deviceId
|
||||
listUrl = "networkdevices.asp?filter=Server"
|
||||
strSQL = "SELECT s.*, v.vendor, m.modelnumber, s.serialnumber, s.ipaddress, NULL AS macaddress, NULL AS idfname, 'Server' AS devicetype, " & _
|
||||
"s.servername AS devicename " & _
|
||||
"FROM servers s " & _
|
||||
"LEFT JOIN models m ON s.modelid = m.modelnumberid " & _
|
||||
strSQL = "SELECT mac.machineid, mac.alias AS servername, mac.machinenotes AS description, " & _
|
||||
"mac.maptop, mac.mapleft, mac.isactive, mac.serialnumber, mac.fqdn, " & _
|
||||
"v.vendor, m.modelnumber, c.address AS ipaddress, c.macaddress, " & _
|
||||
"NULL AS idfname, 'Server' AS devicetype, " & _
|
||||
"mac.alias AS devicename " & _
|
||||
"FROM machines mac " & _
|
||||
"LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _
|
||||
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
|
||||
"WHERE s.serverid = " & CLng(deviceId)
|
||||
"LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"WHERE mac.machineid = " & CLng(deviceId) & " AND mac.machinetypeid = 20"
|
||||
Case "switch"
|
||||
tableName = "switches"
|
||||
idField = "switchid"
|
||||
machineTypeId = 19
|
||||
editUrl = "deviceswitch.asp?id=" & deviceId
|
||||
listUrl = "networkdevices.asp?filter=Switch"
|
||||
strSQL = "SELECT s.*, v.vendor, m.modelnumber, s.serialnumber, s.ipaddress, NULL AS macaddress, NULL AS idfname, 'Switch' AS devicetype, " & _
|
||||
"s.switchname AS devicename " & _
|
||||
"FROM switches s " & _
|
||||
"LEFT JOIN models m ON s.modelid = m.modelnumberid " & _
|
||||
strSQL = "SELECT mac.machineid, mac.alias AS switchname, mac.machinenotes AS description, " & _
|
||||
"mac.maptop, mac.mapleft, mac.isactive, mac.serialnumber, mac.fqdn, " & _
|
||||
"v.vendor, m.modelnumber, c.address AS ipaddress, c.macaddress, " & _
|
||||
"NULL AS idfname, 'Switch' AS devicetype, " & _
|
||||
"mac.alias AS devicename " & _
|
||||
"FROM machines mac " & _
|
||||
"LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _
|
||||
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
|
||||
"WHERE s.switchid = " & CLng(deviceId)
|
||||
"LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"WHERE mac.machineid = " & CLng(deviceId) & " AND mac.machinetypeid = 19"
|
||||
Case "camera"
|
||||
tableName = "cameras"
|
||||
idField = "cameraid"
|
||||
machineTypeId = 17
|
||||
editUrl = "devicecamera.asp?id=" & deviceId
|
||||
listUrl = "networkdevices.asp?filter=Camera"
|
||||
strSQL = "SELECT c.*, v.vendor, m.modelnumber, c.serialnumber, c.ipaddress, c.macaddress, i.idfname, 'Camera' AS devicetype, " & _
|
||||
"c.cameraname AS devicename " & _
|
||||
"FROM cameras c " & _
|
||||
"LEFT JOIN models m ON c.modelid = m.modelnumberid " & _
|
||||
strSQL = "SELECT mac.machineid, mac.alias AS cameraname, mac.machinenotes AS description, " & _
|
||||
"mac.maptop, mac.mapleft, mac.isactive, mac.serialnumber, mac.fqdn, " & _
|
||||
"v.vendor, m.modelnumber, c.address AS ipaddress, c.macaddress, " & _
|
||||
"idf.alias AS idfname, idf.machineid AS idfid, 'Camera' AS devicetype, " & _
|
||||
"mac.alias AS devicename " & _
|
||||
"FROM machines mac " & _
|
||||
"LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _
|
||||
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
|
||||
"LEFT JOIN idfs i ON c.idfid = i.idfid " & _
|
||||
"WHERE c.cameraid = " & CLng(deviceId)
|
||||
"LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"LEFT JOIN machinerelationships mr ON mac.machineid = mr.machineid AND mr.isactive = 1 " & _
|
||||
"LEFT JOIN machines idf ON mr.related_machineid = idf.machineid AND idf.machinetypeid = 18 " & _
|
||||
"WHERE mac.machineid = " & CLng(deviceId) & " AND mac.machinetypeid = 17"
|
||||
Case "accesspoint", "access point"
|
||||
tableName = "accesspoints"
|
||||
idField = "apid"
|
||||
machineTypeId = 16
|
||||
editUrl = "deviceaccesspoint.asp?id=" & deviceId
|
||||
listUrl = "networkdevices.asp?filter=Access Point"
|
||||
strSQL = "SELECT ap.apid, ap.apname AS devicename, ap.modelid, ap.serialnumber, ap.ipaddress, ap.description, ap.maptop, ap.mapleft, ap.isactive, " & _
|
||||
"v.vendor, m.modelnumber, NULL AS macaddress, NULL AS idfname, NULL AS idfid, 'Access Point' AS devicetype " & _
|
||||
"FROM accesspoints ap " & _
|
||||
"LEFT JOIN models m ON ap.modelid = m.modelnumberid " & _
|
||||
strSQL = "SELECT mac.machineid AS apid, mac.alias AS devicename, mac.modelnumberid AS modelid, " & _
|
||||
"mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _
|
||||
"v.vendor, m.modelnumber, c.address AS ipaddress, c.macaddress, " & _
|
||||
"NULL AS idfname, NULL AS idfid, 'Access Point' AS devicetype " & _
|
||||
"FROM machines mac " & _
|
||||
"LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _
|
||||
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
|
||||
"WHERE ap.apid = " & CLng(deviceId)
|
||||
"LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"WHERE mac.machineid = " & CLng(deviceId) & " AND mac.machinetypeid = 16"
|
||||
Case Else
|
||||
Response.Redirect("networkdevices.asp")
|
||||
Response.End
|
||||
|
||||
Reference in New Issue
Block a user