diff --git a/sql/naming_convention_fix/05_update_asp_files.ps1 b/sql/naming_convention_fix/05_update_asp_files.ps1 new file mode 100644 index 0000000..21fcd8d --- /dev/null +++ b/sql/naming_convention_fix/05_update_asp_files.ps1 @@ -0,0 +1,124 @@ +# ============================================================================ +# Script: 05_update_asp_files.ps1 +# Purpose: Update ASP files to use new table names +# Target: ShopDB ASP files on Windows +# +# USAGE: +# cd C:\path\to\shopdb +# .\sql\naming_convention_fix\05_update_asp_files.ps1 +# .\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute +# ============================================================================ + +param( + [switch]$Execute +) + +Write-Host "============================================" -ForegroundColor Cyan +Write-Host "ASP File Table Name Updates" -ForegroundColor Cyan +Write-Host "============================================" -ForegroundColor Cyan +Write-Host "" + +# Define replacements (old -> new) +$replacements = @{ + "machine_overrides" = "machineoverrides" + "pc_comm_config" = "commconfig" + "pc_dnc_config" = "dncconfig" + "pc_dualpath_assignments" = "dualpathassignments" + "pc_network_interfaces" = "networkinterfaces" + "usb_checkouts" = "usbcheckouts" +} + +# Files to update (from impact analysis) +$fileTables = @{ + "api.asp" = @("pc_comm_config", "pc_dnc_config") + "displaypc.asp" = @("pc_network_interfaces") + "displaysubnet.asp" = @("pc_network_interfaces") + "displaymachine.asp" = @("pc_network_interfaces") + "usb_history.asp" = @("usb_checkouts") + "savecheckin_usb.asp" = @("usb_checkouts") + "displayprofile.asp" = @("usb_checkouts") + "displayusb.asp" = @("usb_checkouts") + "savecheckout_usb.asp" = @("usb_checkouts") + "api_usb.asp" = @("usb_checkouts") +} + +Write-Host "Changes to be made:" -ForegroundColor Yellow +Write-Host "" + +foreach ($file in $fileTables.Keys) { + $filepath = Join-Path $PSScriptRoot "..\..\$file" + + if (Test-Path $filepath) { + $content = Get-Content $filepath -Raw + $tables = $fileTables[$file] + + Write-Host "--- $file ---" -ForegroundColor Green + + foreach ($table in $tables) { + $newName = $replacements[$table] + $matches = ([regex]::Matches($content, [regex]::Escape($table))).Count + + if ($matches -gt 0) { + Write-Host " $table -> $newName ($matches occurrences)" -ForegroundColor White + + # Show first few matches with line numbers + $lines = Get-Content $filepath + $lineNum = 0 + $shown = 0 + foreach ($line in $lines) { + $lineNum++ + if ($line -match [regex]::Escape($table) -and $shown -lt 3) { + Write-Host " Line $lineNum : $($line.Trim().Substring(0, [Math]::Min(80, $line.Trim().Length)))" -ForegroundColor Gray + $shown++ + } + } + } + } + Write-Host "" + } + else { + Write-Host "WARNING: $file not found!" -ForegroundColor Red + } +} + +if ($Execute) { + Write-Host "" + Write-Host "============================================" -ForegroundColor Cyan + Write-Host "EXECUTING CHANGES..." -ForegroundColor Cyan + Write-Host "============================================" -ForegroundColor Cyan + Write-Host "" + + foreach ($file in $fileTables.Keys) { + $filepath = Join-Path $PSScriptRoot "..\..\$file" + + if (Test-Path $filepath) { + $content = Get-Content $filepath -Raw + $tables = $fileTables[$file] + $modified = $false + + foreach ($table in $tables) { + $newName = $replacements[$table] + if ($content -match [regex]::Escape($table)) { + $content = $content -replace [regex]::Escape($table), $newName + $modified = $true + Write-Host "Updated $file : $table -> $newName" -ForegroundColor Green + } + } + + if ($modified) { + Set-Content -Path $filepath -Value $content -NoNewline + } + } + } + + Write-Host "" + Write-Host "ASP files updated successfully!" -ForegroundColor Green +} +else { + Write-Host "" + Write-Host "============================================" -ForegroundColor Yellow + Write-Host "DRY RUN COMPLETE" -ForegroundColor Yellow + Write-Host "============================================" -ForegroundColor Yellow + Write-Host "To apply changes, run:" -ForegroundColor White + Write-Host " .\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute" -ForegroundColor Cyan +} diff --git a/sql/naming_convention_fix/05_update_asp_files.sh b/sql/naming_convention_fix/05_update_asp_files.sh deleted file mode 100644 index 8ba6cde..0000000 --- a/sql/naming_convention_fix/05_update_asp_files.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -# ============================================================================ -# Script: 05_update_asp_files.sh -# Purpose: Update ASP files to use new table names -# Target: ShopDB ASP files -# -# USAGE: Run from shopdb directory -# cd /path/to/shopdb -# bash sql/naming_convention_fix/05_update_asp_files.sh -# -# This will show what changes will be made. Add --execute to actually apply. -# ============================================================================ - -set -e - -SHOPDB_DIR="${1:-.}" -EXECUTE_MODE="${2:-}" - -echo "============================================" -echo "ASP File Table Name Updates" -echo "============================================" -echo "" - -# Define replacements (old -> new) -declare -A REPLACEMENTS=( - ["machine_overrides"]="machineoverrides" - ["pc_comm_config"]="commconfig" - ["pc_dnc_config"]="dncconfig" - ["pc_dualpath_assignments"]="dualpathassignments" - ["pc_network_interfaces"]="networkinterfaces" - ["usb_checkouts"]="usbcheckouts" -) - -# Files to update (from impact analysis) -declare -A FILE_TABLES=( - ["api.asp"]="pc_comm_config pc_dnc_config" - ["displaypc.asp"]="pc_network_interfaces" - ["displaysubnet.asp"]="pc_network_interfaces" - ["displaymachine.asp"]="pc_network_interfaces" - ["usb_history.asp"]="usb_checkouts" - ["savecheckin_usb.asp"]="usb_checkouts" - ["displayprofile.asp"]="usb_checkouts" - ["displayusb.asp"]="usb_checkouts" - ["savecheckout_usb.asp"]="usb_checkouts" - ["api_usb.asp"]="usb_checkouts" -) - -echo "Changes to be made:" -echo "" - -for file in "${!FILE_TABLES[@]}"; do - filepath="$SHOPDB_DIR/$file" - if [ -f "$filepath" ]; then - tables="${FILE_TABLES[$file]}" - echo "--- $file ---" - for table in $tables; do - new_name="${REPLACEMENTS[$table]}" - matches=$(grep -c "$table" "$filepath" 2>/dev/null || echo "0") - if [ "$matches" -gt 0 ]; then - echo " $table -> $new_name ($matches occurrences)" - grep -n "$table" "$filepath" | head -5 - fi - done - echo "" - else - echo "WARNING: $file not found!" - fi -done - -if [ "$EXECUTE_MODE" == "--execute" ]; then - echo "" - echo "============================================" - echo "EXECUTING CHANGES..." - echo "============================================" - echo "" - - for file in "${!FILE_TABLES[@]}"; do - filepath="$SHOPDB_DIR/$file" - if [ -f "$filepath" ]; then - tables="${FILE_TABLES[$file]}" - for table in $tables; do - new_name="${REPLACEMENTS[$table]}" - sed -i "s/$table/$new_name/g" "$filepath" - echo "Updated $file: $table -> $new_name" - done - fi - done - - echo "" - echo "ASP files updated successfully!" -else - echo "" - echo "============================================" - echo "DRY RUN COMPLETE" - echo "============================================" - echo "To apply changes, run:" - echo " bash sql/naming_convention_fix/05_update_asp_files.sh . --execute" -fi diff --git a/sql/naming_convention_fix/06_update_docs.ps1 b/sql/naming_convention_fix/06_update_docs.ps1 new file mode 100644 index 0000000..fe77d8e --- /dev/null +++ b/sql/naming_convention_fix/06_update_docs.ps1 @@ -0,0 +1,107 @@ +# ============================================================================ +# Script: 06_update_docs.ps1 +# Purpose: Update documentation files to reference new table names +# Target: ShopDB markdown files on Windows +# +# USAGE: +# cd C:\path\to\shopdb +# .\sql\naming_convention_fix\06_update_docs.ps1 +# .\sql\naming_convention_fix\06_update_docs.ps1 -Execute +# +# This is lower priority - docs can be updated anytime after migration +# ============================================================================ + +param( + [switch]$Execute +) + +Write-Host "============================================" -ForegroundColor Cyan +Write-Host "Documentation Table Name Updates" -ForegroundColor Cyan +Write-Host "============================================" -ForegroundColor Cyan +Write-Host "" + +# Define replacements +$replacements = @{ + "machine_overrides" = "machineoverrides" + "pc_comm_config" = "commconfig" + "pc_dnc_config" = "dncconfig" + "pc_dualpath_assignments" = "dualpathassignments" + "pc_network_interfaces" = "networkinterfaces" + "usb_checkouts" = "usbcheckouts" +} + +# Get the shopdb root directory (two levels up from script location) +$shopdbRoot = Join-Path $PSScriptRoot "..\..\" + +Write-Host "Searching for documentation files with old table names..." -ForegroundColor Yellow +Write-Host "Directory: $shopdbRoot" -ForegroundColor Gray +Write-Host "" + +# Find all markdown files +$mdFiles = Get-ChildItem -Path $shopdbRoot -Filter "*.md" -Recurse -ErrorAction SilentlyContinue + +$filesToUpdate = @{} + +foreach ($oldName in $replacements.Keys) { + $newName = $replacements[$oldName] + Write-Host "--- $oldName -> $newName ---" -ForegroundColor Green + + $matchingFiles = @() + + foreach ($file in $mdFiles) { + $content = Get-Content $file.FullName -Raw -ErrorAction SilentlyContinue + if ($content -match [regex]::Escape($oldName)) { + $count = ([regex]::Matches($content, [regex]::Escape($oldName))).Count + $relativePath = $file.FullName.Replace((Resolve-Path $shopdbRoot).Path, "") + Write-Host " $relativePath ($count occurrences)" -ForegroundColor White + + if (-not $filesToUpdate.ContainsKey($file.FullName)) { + $filesToUpdate[$file.FullName] = @() + } + $filesToUpdate[$file.FullName] += $oldName + } + } + + if ($matchingFiles.Count -eq 0) { + # Already printed matches above + } + Write-Host "" +} + +Write-Host "Total files to update: $($filesToUpdate.Count)" -ForegroundColor Yellow +Write-Host "" + +if ($Execute) { + Write-Host "============================================" -ForegroundColor Cyan + Write-Host "EXECUTING CHANGES..." -ForegroundColor Cyan + Write-Host "============================================" -ForegroundColor Cyan + Write-Host "" + + foreach ($filePath in $filesToUpdate.Keys) { + $content = Get-Content $filePath -Raw + + foreach ($oldName in $replacements.Keys) { + $newName = $replacements[$oldName] + if ($content -match [regex]::Escape($oldName)) { + $content = $content -replace [regex]::Escape($oldName), $newName + } + } + + Set-Content -Path $filePath -Value $content -NoNewline + $relativePath = $filePath.Replace((Resolve-Path $shopdbRoot).Path, "") + Write-Host "Updated: $relativePath" -ForegroundColor Green + } + + Write-Host "" + Write-Host "Documentation updated successfully!" -ForegroundColor Green +} +else { + Write-Host "============================================" -ForegroundColor Yellow + Write-Host "DRY RUN COMPLETE" -ForegroundColor Yellow + Write-Host "============================================" -ForegroundColor Yellow + Write-Host "To apply changes, run:" -ForegroundColor White + Write-Host " .\sql\naming_convention_fix\06_update_docs.ps1 -Execute" -ForegroundColor Cyan + Write-Host "" + Write-Host "NOTE: Documentation updates are low priority." -ForegroundColor Gray + Write-Host " Focus on database and ASP changes first." -ForegroundColor Gray +} diff --git a/sql/naming_convention_fix/06_update_docs.sh b/sql/naming_convention_fix/06_update_docs.sh deleted file mode 100644 index abf64c4..0000000 --- a/sql/naming_convention_fix/06_update_docs.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# ============================================================================ -# Script: 06_update_docs.sh -# Purpose: Update documentation files to reference new table names -# Target: ShopDB and PowerShell-scripts repos -# -# USAGE: -# cd /path/to/shopdb -# bash sql/naming_convention_fix/06_update_docs.sh [--execute] -# -# This is lower priority - docs can be updated anytime after migration -# ============================================================================ - -set -e - -EXECUTE_MODE="${1:-}" - -echo "============================================" -echo "Documentation Table Name Updates" -echo "============================================" -echo "" - -# Define replacements -declare -A REPLACEMENTS=( - ["machine_overrides"]="machineoverrides" - ["pc_comm_config"]="commconfig" - ["pc_dnc_config"]="dncconfig" - ["pc_dualpath_assignments"]="dualpathassignments" - ["pc_network_interfaces"]="networkinterfaces" - ["usb_checkouts"]="usbcheckouts" -) - -echo "Searching for documentation files with old table names..." -echo "" - -# Find all md files with old table names -for old_name in "${!REPLACEMENTS[@]}"; do - new_name="${REPLACEMENTS[$old_name]}" - echo "--- $old_name -> $new_name ---" - - # Search in current directory and subdirectories - files=$(grep -rl "$old_name" --include="*.md" . 2>/dev/null || true) - - if [ -n "$files" ]; then - for f in $files; do - count=$(grep -c "$old_name" "$f" 2>/dev/null || echo "0") - echo " $f ($count occurrences)" - done - else - echo " (no matches)" - fi - echo "" -done - -if [ "$EXECUTE_MODE" == "--execute" ]; then - echo "============================================" - echo "EXECUTING CHANGES..." - echo "============================================" - echo "" - - for old_name in "${!REPLACEMENTS[@]}"; do - new_name="${REPLACEMENTS[$old_name]}" - # Update all md files - find . -name "*.md" -type f -exec sed -i "s/$old_name/$new_name/g" {} \; - echo "Updated all .md files: $old_name -> $new_name" - done - - echo "" - echo "Documentation updated successfully!" -else - echo "============================================" - echo "DRY RUN COMPLETE" - echo "============================================" - echo "To apply changes, run:" - echo " bash sql/naming_convention_fix/06_update_docs.sh --execute" - echo "" - echo "NOTE: Documentation updates are low priority." - echo " Focus on database and ASP changes first." -fi diff --git a/sql/naming_convention_fix/PRODUCTION_DEPLOYMENT_GUIDE.md b/sql/naming_convention_fix/PRODUCTION_DEPLOYMENT_GUIDE.md index 3ad4259..752ff91 100644 --- a/sql/naming_convention_fix/PRODUCTION_DEPLOYMENT_GUIDE.md +++ b/sql/naming_convention_fix/PRODUCTION_DEPLOYMENT_GUIDE.md @@ -108,9 +108,13 @@ This guide covers migrating table names from `snake_case` to `camelCase` to matc SELECT COUNT(*) FROM vw_active_pcs; ``` -8. **Deploy updated ASP files** - - Copy updated ASP files to IIS web directory - - Or pull from git +8. **Update ASP files using PowerShell script** + ```powershell + cd C:\path\to\shopdb + .\sql\naming_convention_fix\05_update_asp_files.ps1 # Dry run - shows changes + .\sql\naming_convention_fix\05_update_asp_files.ps1 -Execute # Apply changes + ``` + Or manually copy pre-updated ASP files from git 9. **Start IIS** ```cmd @@ -131,6 +135,10 @@ This guide covers migrating table names from `snake_case` to `camelCase` to matc ``` 2. **Update documentation** (low priority, can do anytime) + ```powershell + .\sql\naming_convention_fix\06_update_docs.ps1 # Dry run + .\sql\naming_convention_fix\06_update_docs.ps1 -Execute # Apply changes + ``` ---