This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository contains both MySQL and PostgreSQL database management shell scripts for clearing database tables and importing SQL files. The scripts provide interactive menus with progress bars, logging, and safety confirmations for destructive operations. Both database platforms offer identical professional interfaces and functionality.
- mysql_db_management.sh: Basic version requiring manual DB_USER/DB_PASS configuration (334 lines)
- mysql_db_management_mac.sh: macOS version with automatic MySQL client detection (341 lines)
- mysql_db_management_mac_os_laravel-herd.sh: Enhanced Laravel Herd compatibility version with timing and improved UX (522 lines)
- pgsql_db_management_mac_os_laravel-herd.sh: PostgreSQL enhanced version with identical professional UI and functionality (522 lines)
All scripts require these variables to be set:
DB_USER="your_username" # MySQL username
DB_PASS="your_password" # MySQL password
DB_HOST="127.0.0.1" # Database host (mac versions)
DB_PORT="3306" # Database port (MySQL default)
DOWNLOADS_PATH="$HOME/Downloads" # SQL files locationDB_USER="root" # PostgreSQL username
DB_PASS="" # PostgreSQL password (empty for Laravel Herd default)
DB_HOST="127.0.0.1" # Database host
DB_PORT="5432" # Database port (PostgreSQL default)
DOWNLOADS_PATH="$HOME/Downloads" # SQL files locationThe scripts provide three main operations:
- Clear Database: Drop all tables from selected database (excludes system DBs)
- Import SQL File: Import SQL from Downloads directory into selected database
- Both: Clear database then import SQL file
- MySQL: Excludes system databases: 'information_schema', 'mysql', 'performance_schema', 'sys', 'ploi', 'phpmyadmin'
- PostgreSQL: Excludes system databases: 'template0', 'template1', 'postgres'
- MySQL: Forces foreign key checks off during table drops
- PostgreSQL: Implements CASCADE table dropping for foreign key constraints
- Confirms destructive actions before execution
- Checks for existing data before imports
- Interactive select menus with numbered options
- Colored logging with timestamps
- Progress bars for long operations
- Graceful navigation (Main Menu, Go Back, Quit options)
- Auto-renames SQL files to slug format (removes special characters)
- Lists available SQL files from Downloads directory
- Validates file existence before operations
- Enhanced versions add: File size display, formatted file listing with sizes
- PostgreSQL version supports:
.sql,.dump, and.psqlfile formats - MySQL version supports: Standard
.sqlfiles
To test the scripts:
# Make executable
chmod +x mysql_db_management.sh
# Run with proper DB credentials configured
./mysql_db_management.sh# Make executable
chmod +x pgsql_db_management_mac_os_laravel-herd.sh
# Run with proper PostgreSQL credentials configured
./pgsql_db_management_mac_os_laravel-herd.shThe Laravel Herd version includes significant improvements over the basic versions:
show_header(): Displays formatted header with database connection info and timestampsshow_action_header(): Shows section headers with decorative borderslist_sql_files_with_sizes(): Lists SQL files with their sizes for better selectionformat_file_size(): Converts bytes to human-readable format (B, K, M, G)format_duration(): Formats operation duration in hours/minutes/secondsget_timestamp(): Gets Unix timestamp for timing operations
- Professional bordered headers with system info
- File size display during SQL file selection
- Real-time operation timing and duration reporting
- Enhanced confirmation prompts using specific keywords:
- "YES" for database clearing
- "OVERRIDE" for importing into non-empty databases
- "PROCEED" for combined operations
- Visual indicators: ✓ for success, ⚠ for warnings
- Step-by-step operation progress (Step 1/2, Step 2/2)
- Better error handling with contextual messages
- Operation start/end time display
- Progress dots during import operations
- Enhanced menu navigation with clearer options
- More robust selection mechanism with input validation
- Uses Unicode symbols for better visual feedback
- Implements proper error handling with PIPESTATUS
- Improved MySQL command execution with better output parsing
- Enhanced confirmation workflow prevents accidental operations
The PostgreSQL version includes complete feature parity with the MySQL enhanced version while adapting to PostgreSQL-specific requirements:
- Authentication: Uses
PGPASSWORDenvironment variable for secure password handling - System Catalogs: Queries
pg_databaseandpg_tablesfor database/table information - Schema Focus: Operates exclusively on
publicschema tables - Constraint Handling: Implements
DROP TABLE CASCADEfor foreign key dependencies - Port Configuration: Defaults to PostgreSQL standard port 5432
- Client Detection: Automatic
psqlcommand location and validation - Connection Management: Uses
-h,-p,-U,-dflags for connection parameters - Query Execution: Silent mode (
-t) with proper error handling - File Import: Direct
psqlfile execution with progress monitoring
- Standard SQL:
.sqlfiles (same as MySQL version) - PostgreSQL Dumps:
.dumpfiles frompg_dump - PostgreSQL Scripts:
.psqlfiles with PostgreSQL-specific syntax
- Scripts handle database credentials in plaintext variables
- PostgreSQL: Uses
PGPASSWORDenvironment variable (more secure than command-line passwords) - MySQL: Uses command-line password parameters (less secure, visible in process list)
- Operations are destructive (DROP TABLE/CASCADE) - use with extreme caution
- No backup functionality - users must backup before running
- Designed for development environments, not production use
- Enhanced versions add stronger confirmation mechanisms to prevent accidents
- PostgreSQL CASCADE operations: Can drop dependent objects, requires extra caution