-- ============================================================================
-- 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;
