eDNC: Use machineid instead of hostname for proper FK relationship

- ednclogs table now uses machineid to link to machines table
- Removed redundant hostname storage (derive from machines table)
- Updated LogDNCEvent to look up and insert machineid
- Updated GetDNCStats to join machines table for hostname
- Updated displaypc.asp queries to use machineid directly
- sql/ednc_tables.sql is now a migration script for existing 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:
cproudlock
2025-12-12 09:33:27 -05:00
parent 4441dde2e8
commit a1a10a51d2
3 changed files with 92 additions and 132 deletions

View File

@@ -1,41 +1,25 @@
-- ============================================================================
-- eDNC Special Character Fix - Database Tables
-- Run on PRODUCTION database to enable eDNC logging
-- Created: 2025-12-12
-- eDNC Special Character Fix - Database Migration
-- Migrates ednclogs from hostname to machineid (FK to machines table)
-- Run on PRODUCTION after initial setup
-- Updated: 2025-12-12
-- ============================================================================
-- Log individual events (cleaned, failed, started, stopped, etc.)
CREATE TABLE IF NOT EXISTS ednc_logs (
logid INT AUTO_INCREMENT PRIMARY KEY,
hostname VARCHAR(50) NOT NULL,
filename VARCHAR(255) NOT NULL,
action ENUM('cleaned', 'ok', 'failed', 'error', 'started', 'stopped') NOT NULL,
bytes_removed INT DEFAULT 0,
version VARCHAR(20),
message VARCHAR(500),
created DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_hostname (hostname),
INDEX idx_created (created),
INDEX idx_action (action)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Step 1: Add machineid column to ednclogs
ALTER TABLE ednclogs
ADD COLUMN machineid INT NOT NULL AFTER logid,
ADD INDEX idx_machineid (machineid);
-- Track installations per PC
CREATE TABLE IF NOT EXISTS ednc_installations (
installid INT AUTO_INCREMENT PRIMARY KEY,
hostname VARCHAR(50) NOT NULL UNIQUE,
version VARCHAR(20),
watch_folder VARCHAR(255),
file_filter VARCHAR(50),
first_seen DATETIME DEFAULT CURRENT_TIMESTAMP,
last_seen DATETIME DEFAULT CURRENT_TIMESTAMP,
is_active TINYINT(1) DEFAULT 1,
total_cleaned INT DEFAULT 0,
total_failed INT DEFAULT 0,
INDEX idx_hostname (hostname),
INDEX idx_active (is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Step 2: Populate machineid from hostname (match existing PCs)
UPDATE ednclogs l
INNER JOIN machines m ON UPPER(m.hostname) = UPPER(l.hostname)
SET l.machineid = m.machineid
WHERE m.pctypeid IS NOT NULL;
-- Verify tables created
SELECT 'ednc_logs' AS table_name, COUNT(*) AS row_count FROM ednc_logs
UNION ALL
SELECT 'ednc_installations', COUNT(*) FROM ednc_installations;
-- Step 3: Remove hostname column and index
ALTER TABLE ednclogs DROP INDEX idx_hostname;
ALTER TABLE ednclogs DROP COLUMN hostname;
-- Verify migration
SELECT 'Migration complete' AS status;
DESCRIBE ednclogs;