Add USB checkout system and SSO profile page

New Features:
- USB Device checkout/check-in system with barcode scanning
  - displayusb.asp: List all USB devices with status
  - addusb.asp: Add new USB devices via barcode scan
  - checkout_usb.asp/savecheckout_usb.asp: Check out USB to SSO
  - checkin_usb.asp/savecheckin_usb.asp: Check in with wipe confirmation
  - usb_history.asp: Full checkout history with filters
  - api_usb.asp: JSON API for AJAX lookups
- displayprofile.asp: SSO profile page showing user info and USB history
- Date/time format changed to 12-hour (MM/DD/YYYY h:mm AM/PM)
- SSO links in USB history now link to profile page via search

Database:
- New machinetypeid 44 for USB devices
- New usb_checkouts table for tracking checkouts

Cleanup:
- Removed v2 folder (duplicate/old files)
- Removed old debug/test files
- Removed completed migration documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-07 11:16:14 -05:00
parent c7834d4b99
commit 65b622c361
1061 changed files with 19034 additions and 213120 deletions

View File

@@ -0,0 +1,62 @@
-- =====================================================
-- SCRIPT 01: Create Application Versions Infrastructure
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Create appversions table for tracking application versions
-- Status: REVERSIBLE (see ROLLBACK_01)
-- Estimated Time: < 1 minute
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- =====================================================
-- STEP 1: Create appversions table
-- =====================================================
CREATE TABLE IF NOT EXISTS appversions (
appversionid INT(11) PRIMARY KEY AUTO_INCREMENT,
appid TINYINT(4) NOT NULL,
version VARCHAR(50) NOT NULL,
releasedate DATE NULL,
notes VARCHAR(255) NULL,
isactive BIT(1) DEFAULT b'1',
dateadded DATETIME DEFAULT CURRENT_TIMESTAMP,
-- Indexes
KEY idx_appid (appid),
KEY idx_version (version),
KEY idx_isactive (isactive),
-- Unique constraint: one version string per application
UNIQUE KEY uk_app_version (appid, version),
-- Foreign Key
CONSTRAINT fk_appversions_appid FOREIGN KEY (appid) REFERENCES applications(appid)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
COMMENT='Application version tracking for installed software';
-- =====================================================
-- VERIFICATION
-- =====================================================
SELECT '✓ appversions table created' AS status;
SELECT
TABLE_NAME,
ENGINE,
TABLE_ROWS,
TABLE_COMMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'shopdb' AND TABLE_NAME = 'appversions';
SELECT '✓ Script 01 completed successfully' AS status;
SET SQL_SAFE_UPDATES = 1;
-- =====================================================
-- NOTES
-- =====================================================
-- Next: Run script 02_add_appversionid_to_installedapps.sql
-- Rollback: Run ROLLBACK_01_appversions_table.sql
-- =====================================================

View File

@@ -0,0 +1,102 @@
-- =====================================================
-- SCRIPT 02: Add appversionid to installedapps
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Add version tracking column to installedapps table
-- Status: REVERSIBLE (see ROLLBACK_02)
-- Estimated Time: < 1 minute
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- =====================================================
-- STEP 1: Add appversionid column to installedapps
-- =====================================================
-- Check if column exists before adding
SET @column_exists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND COLUMN_NAME = 'appversionid'
);
SET @sql = IF(@column_exists = 0,
'ALTER TABLE installedapps ADD COLUMN appversionid INT(11) NULL AFTER appid',
'SELECT "Column appversionid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- STEP 2: Add foreign key constraint
-- =====================================================
-- Check if FK exists before adding
SET @fk_exists = (
SELECT COUNT(*)
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND CONSTRAINT_NAME = 'fk_installedapps_appversionid'
);
SET @sql = IF(@fk_exists = 0,
'ALTER TABLE installedapps ADD CONSTRAINT fk_installedapps_appversionid FOREIGN KEY (appversionid) REFERENCES appversions(appversionid) ON DELETE SET NULL ON UPDATE CASCADE',
'SELECT "FK fk_installedapps_appversionid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- STEP 3: Add index for performance
-- =====================================================
SET @idx_exists = (
SELECT COUNT(*)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND INDEX_NAME = 'idx_appversionid'
);
SET @sql = IF(@idx_exists = 0,
'ALTER TABLE installedapps ADD INDEX idx_appversionid (appversionid)',
'SELECT "Index idx_appversionid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- VERIFICATION
-- =====================================================
SELECT '✓ installedapps table updated' AS status;
SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
COLUMN_DEFAULT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
ORDER BY ORDINAL_POSITION;
SELECT '✓ Script 02 completed successfully' AS status;
SET SQL_SAFE_UPDATES = 1;
-- =====================================================
-- NOTES
-- =====================================================
-- Existing installedapps records will have appversionid = NULL
-- PowerShell API will need updating to populate this field
-- Next: Run script 03_add_appid_to_notifications.sql
-- Rollback: Run ROLLBACK_02_installedapps_appversionid.sql
-- =====================================================

View File

@@ -0,0 +1,102 @@
-- =====================================================
-- SCRIPT 03: Add optional appid to notifications
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Allow notifications to be optionally linked to an application
-- Status: REVERSIBLE (see ROLLBACK_03)
-- Estimated Time: < 1 minute
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- =====================================================
-- STEP 1: Add appid column to notifications
-- =====================================================
-- Check if column exists before adding
SET @column_exists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND COLUMN_NAME = 'appid'
);
SET @sql = IF(@column_exists = 0,
'ALTER TABLE notifications ADD COLUMN appid TINYINT(4) NULL AFTER businessunitid',
'SELECT "Column appid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- STEP 2: Add foreign key constraint
-- =====================================================
-- Check if FK exists before adding
SET @fk_exists = (
SELECT COUNT(*)
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND CONSTRAINT_NAME = 'fk_notifications_appid'
);
SET @sql = IF(@fk_exists = 0,
'ALTER TABLE notifications ADD CONSTRAINT fk_notifications_appid FOREIGN KEY (appid) REFERENCES applications(appid) ON DELETE SET NULL ON UPDATE CASCADE',
'SELECT "FK fk_notifications_appid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- STEP 3: Add index for performance
-- =====================================================
SET @idx_exists = (
SELECT COUNT(*)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND INDEX_NAME = 'idx_notifications_appid'
);
SET @sql = IF(@idx_exists = 0,
'ALTER TABLE notifications ADD INDEX idx_notifications_appid (appid)',
'SELECT "Index idx_notifications_appid already exists" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =====================================================
-- VERIFICATION
-- =====================================================
SELECT '✓ notifications table updated' AS status;
SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
COLUMN_DEFAULT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
ORDER BY ORDINAL_POSITION;
SELECT '✓ Script 03 completed successfully' AS status;
SET SQL_SAFE_UPDATES = 1;
-- =====================================================
-- NOTES
-- =====================================================
-- appid is optional (NULL allowed) - most notifications won't be app-specific
-- Use case: "PC-DMIS upgrade scheduled" notification linked to PC-DMIS app
-- Next: Run VERIFY_PHASE4_MIGRATION.sql
-- Rollback: Run ROLLBACK_03_notifications_appid.sql
-- =====================================================

View File

@@ -0,0 +1,177 @@
# Phase 4 Migration: Application Versions
**Date:** 2025-11-25
**Status:** Ready for deployment
## Overview
This migration adds application version tracking to ShopDB:
1. **`appversions` table** - Stores version strings for each application
2. **`installedapps.appversionid`** - Links installed apps to specific versions
3. **`notifications.appid`** - Optional link from notifications to applications
## Schema Changes
### New Table: appversions
```sql
CREATE TABLE appversions (
appversionid INT PRIMARY KEY AUTO_INCREMENT,
appid TINYINT(4) NOT NULL, -- FK to applications
version VARCHAR(50) NOT NULL, -- Version string (e.g., "2.1.0.45")
releasedate DATE NULL, -- Optional release date
notes VARCHAR(255) NULL, -- Optional notes
isactive BIT(1) DEFAULT 1,
dateadded DATETIME DEFAULT NOW(),
UNIQUE KEY (appid, version) -- One entry per app+version combo
);
```
### Modified Table: installedapps
```sql
-- Added column:
appversionid INT NULL -- FK to appversions (NULL for legacy records)
```
### Modified Table: notifications
```sql
-- Added column:
appid TINYINT(4) NULL -- FK to applications (optional app association)
```
## Files
| File | Purpose |
|------|---------|
| `01_create_appversions_table.sql` | Creates the appversions table |
| `02_add_appversionid_to_installedapps.sql` | Adds version FK to installedapps |
| `03_add_appid_to_notifications.sql` | Adds app FK to notifications |
| `VERIFY_PHASE4_MIGRATION.sql` | Verifies all changes |
| `RUN_ALL_PHASE4_SCRIPTS.sql` | Runs all scripts in order |
| `ROLLBACK_01_appversions_table.sql` | Drops appversions table |
| `ROLLBACK_02_installedapps_appversionid.sql` | Removes installedapps column |
| `ROLLBACK_03_notifications_appid.sql` | Removes notifications column |
## Deployment Instructions
### Prerequisites
1. Create database backup:
```bash
mysqldump -u root -p shopdb > shopdb_backup_$(date +%Y%m%d_%H%M%S).sql
```
2. Verify current schema:
```bash
mysql -u root -p shopdb -e "DESCRIBE installedapps; DESCRIBE notifications;"
```
### Run Migration
**Option A: Run all scripts at once**
```bash
cd /path/to/sql/migration_phase4
mysql -u root -p shopdb < RUN_ALL_PHASE4_SCRIPTS.sql
```
**Option B: Run scripts individually**
```bash
mysql -u root -p shopdb < 01_create_appversions_table.sql
mysql -u root -p shopdb < 02_add_appversionid_to_installedapps.sql
mysql -u root -p shopdb < 03_add_appid_to_notifications.sql
mysql -u root -p shopdb < VERIFY_PHASE4_MIGRATION.sql
```
### Verify Success
```bash
mysql -u root -p shopdb < VERIFY_PHASE4_MIGRATION.sql
```
All checks should show `✓ PASS`.
## Rollback Instructions
If you need to rollback, run scripts in reverse order:
```bash
mysql -u root -p shopdb < ROLLBACK_03_notifications_appid.sql
mysql -u root -p shopdb < ROLLBACK_02_installedapps_appversionid.sql
mysql -u root -p shopdb < ROLLBACK_01_appversions_table.sql
```
**Warning:** Rolling back `ROLLBACK_01` will delete all version data.
## Post-Migration: Code Changes Required
### 1. api.asp - Update GetOrCreateApplication()
The function needs to:
- Look up or create the application in `applications`
- Look up or create the version in `appversions`
- Return `appversionid` to store in `installedapps`
### 2. api.asp - Update UpdateInstalledApps()
Change INSERT to include `appversionid`:
```sql
INSERT INTO installedapps (machineid, appid, appversionid, isactive)
VALUES (?, ?, ?, ?)
```
### 3. Notification forms (addnotification.asp, editnotification.asp)
Add optional application dropdown to link notifications to apps.
### 4. Display pages
- `displayinstalledapps.asp` - Show version column
- `displaynotifications.asp` - Show linked app name
## Example Queries
### Get installed apps with versions
```sql
SELECT
m.hostname,
a.appname,
av.version,
ia.isactive
FROM installedapps ia
JOIN machines m ON ia.machineid = m.machineid
JOIN applications a ON ia.appid = a.appid
LEFT JOIN appversions av ON ia.appversionid = av.appversionid
WHERE m.pctypeid IS NOT NULL
ORDER BY m.hostname, a.appname;
```
### Get notifications with linked apps
```sql
SELECT
n.notification,
n.starttime,
n.endtime,
a.appname AS related_app
FROM notifications n
LEFT JOIN applications a ON n.appid = a.appid
WHERE n.isactive = 1
ORDER BY n.starttime DESC;
```
### Find all versions of a specific app
```sql
SELECT
a.appname,
av.version,
av.releasedate,
COUNT(ia.machineid) AS install_count
FROM applications a
JOIN appversions av ON a.appid = av.appid
LEFT JOIN installedapps ia ON av.appversionid = ia.appversionid
WHERE a.appname LIKE '%PC-DMIS%'
GROUP BY a.appid, av.appversionid
ORDER BY av.version DESC;
```

View File

@@ -0,0 +1,34 @@
-- =====================================================
-- ROLLBACK 01: Remove appversions table
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Rollback script for 01_create_appversions_table.sql
-- WARNING: This will delete all version data!
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- Must remove FK from installedapps first (if it exists)
SET @fk_exists = (
SELECT COUNT(*)
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND CONSTRAINT_NAME = 'fk_installedapps_appversionid'
);
SET @sql = IF(@fk_exists > 0,
'ALTER TABLE installedapps DROP FOREIGN KEY fk_installedapps_appversionid',
'SELECT "FK does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop appversions table
DROP TABLE IF EXISTS appversions;
SELECT '✓ appversions table dropped' AS status;
SET SQL_SAFE_UPDATES = 1;

View File

@@ -0,0 +1,64 @@
-- =====================================================
-- ROLLBACK 02: Remove appversionid from installedapps
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Rollback script for 02_add_appversionid_to_installedapps.sql
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- Drop FK first
SET @fk_exists = (
SELECT COUNT(*)
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND CONSTRAINT_NAME = 'fk_installedapps_appversionid'
);
SET @sql = IF(@fk_exists > 0,
'ALTER TABLE installedapps DROP FOREIGN KEY fk_installedapps_appversionid',
'SELECT "FK does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop index
SET @idx_exists = (
SELECT COUNT(*)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND INDEX_NAME = 'idx_appversionid'
);
SET @sql = IF(@idx_exists > 0,
'ALTER TABLE installedapps DROP INDEX idx_appversionid',
'SELECT "Index does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop column
SET @column_exists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND COLUMN_NAME = 'appversionid'
);
SET @sql = IF(@column_exists > 0,
'ALTER TABLE installedapps DROP COLUMN appversionid',
'SELECT "Column does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT '✓ appversionid removed from installedapps' AS status;
SET SQL_SAFE_UPDATES = 1;

View File

@@ -0,0 +1,64 @@
-- =====================================================
-- ROLLBACK 03: Remove appid from notifications
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Rollback script for 03_add_appid_to_notifications.sql
-- =====================================================
USE shopdb;
SET SQL_SAFE_UPDATES = 0;
-- Drop FK first
SET @fk_exists = (
SELECT COUNT(*)
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND CONSTRAINT_NAME = 'fk_notifications_appid'
);
SET @sql = IF(@fk_exists > 0,
'ALTER TABLE notifications DROP FOREIGN KEY fk_notifications_appid',
'SELECT "FK does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop index
SET @idx_exists = (
SELECT COUNT(*)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND INDEX_NAME = 'idx_notifications_appid'
);
SET @sql = IF(@idx_exists > 0,
'ALTER TABLE notifications DROP INDEX idx_notifications_appid',
'SELECT "Index does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop column
SET @column_exists = (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND COLUMN_NAME = 'appid'
);
SET @sql = IF(@column_exists > 0,
'ALTER TABLE notifications DROP COLUMN appid',
'SELECT "Column does not exist" AS status'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT '✓ appid removed from notifications' AS status;
SET SQL_SAFE_UPDATES = 1;

View File

@@ -0,0 +1,75 @@
-- =====================================================
-- RUN ALL PHASE 4 SCRIPTS: Application Versions
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Execute all Phase 4 migration scripts in order
--
-- USAGE:
-- mysql -u root -p shopdb < RUN_ALL_PHASE4_SCRIPTS.sql
--
-- OR run each script individually:
-- 1. 01_create_appversions_table.sql
-- 2. 02_add_appversionid_to_installedapps.sql
-- 3. 03_add_appid_to_notifications.sql
-- 4. VERIFY_PHASE4_MIGRATION.sql
--
-- ROLLBACK ORDER (if needed):
-- 1. ROLLBACK_03_notifications_appid.sql
-- 2. ROLLBACK_02_installedapps_appversionid.sql
-- 3. ROLLBACK_01_appversions_table.sql
-- =====================================================
USE shopdb;
SELECT '=================================================' AS '';
SELECT 'PHASE 4 MIGRATION: Application Versions' AS '';
SELECT 'Started at: ' AS '', NOW() AS timestamp;
SELECT '=================================================' AS '';
-- =====================================================
-- PRE-MIGRATION BACKUP REMINDER
-- =====================================================
SELECT 'REMINDER: Ensure you have a database backup before proceeding!' AS '';
SELECT '' AS '';
-- =====================================================
-- SCRIPT 1: Create appversions table
-- =====================================================
SELECT '--- Running Script 01: Create appversions table ---' AS '';
SOURCE 01_create_appversions_table.sql;
-- =====================================================
-- SCRIPT 2: Add appversionid to installedapps
-- =====================================================
SELECT '--- Running Script 02: Add appversionid to installedapps ---' AS '';
SOURCE 02_add_appversionid_to_installedapps.sql;
-- =====================================================
-- SCRIPT 3: Add appid to notifications
-- =====================================================
SELECT '--- Running Script 03: Add appid to notifications ---' AS '';
SOURCE 03_add_appid_to_notifications.sql;
-- =====================================================
-- VERIFICATION
-- =====================================================
SELECT '--- Running Verification ---' AS '';
SOURCE VERIFY_PHASE4_MIGRATION.sql;
-- =====================================================
-- COMPLETE
-- =====================================================
SELECT '=================================================' AS '';
SELECT 'PHASE 4 MIGRATION COMPLETE' AS '';
SELECT 'Finished at: ' AS '', NOW() AS timestamp;
SELECT '=================================================' AS '';
SELECT '' AS '';
SELECT 'NEXT STEPS:' AS '';
SELECT '1. Update api.asp to use appversions table' AS '';
SELECT '2. Update PowerShell script to send version data' AS '';
SELECT '3. Update notification forms to allow app selection' AS '';
SELECT '=================================================' AS '';

View File

@@ -0,0 +1,127 @@
-- =====================================================
-- VERIFY PHASE 4 MIGRATION: Application Versions
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Verify all Phase 4 schema changes are in place
-- Run this after all migration scripts complete
-- =====================================================
USE shopdb;
SELECT '=================================================' AS '';
SELECT 'PHASE 4 MIGRATION VERIFICATION' AS '';
SELECT '=================================================' AS '';
-- =====================================================
-- CHECK 1: appversions table exists
-- =====================================================
SELECT '--- CHECK 1: appversions table ---' AS '';
SELECT
CASE WHEN COUNT(*) > 0 THEN '✓ PASS' ELSE '✗ FAIL' END AS appversions_table_exists
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'shopdb' AND TABLE_NAME = 'appversions';
SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
COLUMN_KEY
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb' AND TABLE_NAME = 'appversions'
ORDER BY ORDINAL_POSITION;
-- =====================================================
-- CHECK 2: installedapps.appversionid column exists
-- =====================================================
SELECT '--- CHECK 2: installedapps.appversionid column ---' AS '';
SELECT
CASE WHEN COUNT(*) > 0 THEN '✓ PASS' ELSE '✗ FAIL' END AS appversionid_column_exists
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND COLUMN_NAME = 'appversionid';
-- Check FK
SELECT
CASE WHEN COUNT(*) > 0 THEN '✓ PASS' ELSE '✗ FAIL' END AS installedapps_fk_exists
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'installedapps'
AND CONSTRAINT_NAME = 'fk_installedapps_appversionid';
-- =====================================================
-- CHECK 3: notifications.appid column exists
-- =====================================================
SELECT '--- CHECK 3: notifications.appid column ---' AS '';
SELECT
CASE WHEN COUNT(*) > 0 THEN '✓ PASS' ELSE '✗ FAIL' END AS notifications_appid_column_exists
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND COLUMN_NAME = 'appid';
-- Check FK
SELECT
CASE WHEN COUNT(*) > 0 THEN '✓ PASS' ELSE '✗ FAIL' END AS notifications_appid_fk_exists
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'shopdb'
AND TABLE_NAME = 'notifications'
AND CONSTRAINT_NAME = 'fk_notifications_appid';
-- =====================================================
-- CHECK 4: Foreign key relationships
-- =====================================================
SELECT '--- CHECK 4: Foreign key relationships ---' AS '';
SELECT
CONSTRAINT_NAME,
TABLE_NAME,
REFERENCED_TABLE_NAME
FROM information_schema.REFERENTIAL_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = 'shopdb'
AND (
CONSTRAINT_NAME LIKE '%appversion%'
OR (TABLE_NAME = 'notifications' AND CONSTRAINT_NAME LIKE '%appid%')
);
-- =====================================================
-- SUMMARY: Current record counts
-- =====================================================
SELECT '--- SUMMARY: Record counts ---' AS '';
SELECT
'applications' AS table_name,
COUNT(*) AS record_count
FROM applications
UNION ALL
SELECT
'appversions' AS table_name,
COUNT(*) AS record_count
FROM appversions
UNION ALL
SELECT
'installedapps' AS table_name,
COUNT(*) AS record_count
FROM installedapps
UNION ALL
SELECT
'installedapps (with version)' AS table_name,
COUNT(*) AS record_count
FROM installedapps WHERE appversionid IS NOT NULL
UNION ALL
SELECT
'notifications' AS table_name,
COUNT(*) AS record_count
FROM notifications
UNION ALL
SELECT
'notifications (app-linked)' AS table_name,
COUNT(*) AS record_count
FROM notifications WHERE appid IS NOT NULL;
SELECT '=================================================' AS '';
SELECT 'PHASE 4 VERIFICATION COMPLETE' AS '';
SELECT '=================================================' AS '';

View File

@@ -0,0 +1,32 @@
-- ============================================================================
-- Migration: Add Specialized PC Machine Types
-- Date: 2025-12-03
-- Purpose: Add PC types for CMM, Wax Trace, and Measuring Tool PCs
--
-- These PC types allow categorization of PCs based on installed software:
-- - PC - CMM: PCs running PC-DMIS for CMM measurement
-- - PC - Wax Trace: PCs running Formtracepak for wax trace inspection
-- - PC - Measuring Tool: PCs running Keyence/Genspect for measurement
--
-- This enables proper PC-to-Equipment relationships:
-- - PC - CMM (41) <-> CMM equipment (machinetypeid 3)
-- - PC - Wax Trace (42) <-> Wax Trace equipment (machinetypeid 5)
-- - PC - Measuring Tool (43) <-> Measuring Machine equipment (machinetypeid 23)
-- ============================================================================
-- Add new specialized PC machine types
INSERT INTO machinetypes (machinetypeid, machinetype, isactive, functionalaccountid, bgcolor, machinedescription)
VALUES
(41, 'PC - CMM', 1, NULL, NULL, 'PC running PC-DMIS for CMM measurement'),
(42, 'PC - Wax Trace', 1, NULL, NULL, 'PC running Formtracepak for wax trace inspection'),
(43, 'PC - Measuring Tool', 1, NULL, NULL, 'PC running Keyence/Genspect for measurement')
ON DUPLICATE KEY UPDATE
machinetype = VALUES(machinetype),
machinedescription = VALUES(machinedescription),
isactive = 1;
-- Verify the changes
SELECT machinetypeid, machinetype, machinedescription, isactive
FROM machinetypes
WHERE machinetypeid IN (41, 42, 43)
ORDER BY machinetypeid;

View File

@@ -0,0 +1,33 @@
-- TV Dashboard Slides Management
-- Run this script to create the tables for TV slide management
-- Table to store slide presentations/folders
CREATE TABLE IF NOT EXISTS tv_presentations (
presentationid INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
folder_path VARCHAR(500) NOT NULL COMMENT 'Full path or subfolder name under base path',
interval_seconds INT DEFAULT 10 COMMENT 'Seconds between slides',
isactive TINYINT(1) DEFAULT 0 COMMENT 'Only one should be active at a time',
created_date DATETIME DEFAULT CURRENT_TIMESTAMP,
lastupdated DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
notes VARCHAR(500)
);
-- Table to store individual slides (optional - for when you want to manage slides in DB)
CREATE TABLE IF NOT EXISTS tv_slides (
slideid INT AUTO_INCREMENT PRIMARY KEY,
presentationid INT NOT NULL,
filename VARCHAR(255) NOT NULL,
display_order INT DEFAULT 0,
isactive TINYINT(1) DEFAULT 1,
created_date DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (presentationid) REFERENCES tv_presentations(presentationid) ON DELETE CASCADE
);
-- Insert default presentation
INSERT INTO tv_presentations (name, folder_path, interval_seconds, isactive, notes)
VALUES ('Default', 'S:\\ProcessData\\CommDisplay\\ShopSS', 10, 1, 'Default presentation folder');
-- Example: Add a holiday presentation (inactive by default)
-- INSERT INTO tv_presentations (name, folder_path, interval_seconds, isactive, notes)
-- VALUES ('Christmas 2025', 'Christmas2025', 10, 0, 'Holiday slides - subfolder of base path');