35 lines
1.3 KiB
Bash
Executable File
35 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Compare database counts with exported SQL file counts
|
|
# Usage: ./validate_export.sh
|
|
|
|
set -e
|
|
|
|
echo "Validating exported SQL files against database..."
|
|
echo ""
|
|
|
|
# Get counts from database
|
|
DB_ENGINES=$(docker exec mvp-postgres psql -U postgres -d motovaultpro -t -A -c "SELECT COUNT(*) FROM engines;")
|
|
DB_TRANS=$(docker exec mvp-postgres psql -U postgres -d motovaultpro -t -A -c "SELECT COUNT(*) FROM transmissions;")
|
|
DB_VEHICLES=$(docker exec mvp-postgres psql -U postgres -d motovaultpro -t -A -c "SELECT COUNT(*) FROM vehicle_options;")
|
|
|
|
# Count records in SQL files (count lines starting with '(' which are data rows)
|
|
SQL_ENGINES=$(grep -c '^(' output/01_engines.sql)
|
|
SQL_TRANS=$(grep -c '^(' output/02_transmissions.sql)
|
|
SQL_VEHICLES=$(grep -c '^(' output/03_vehicle_options.sql)
|
|
|
|
# Display comparison
|
|
echo "Database vs SQL File Counts:"
|
|
echo " Engines: $DB_ENGINES (DB) vs $SQL_ENGINES (SQL)"
|
|
echo " Transmissions: $DB_TRANS (DB) vs $SQL_TRANS (SQL)"
|
|
echo " Vehicle Options: $DB_VEHICLES (DB) vs $SQL_VEHICLES (SQL)"
|
|
echo ""
|
|
|
|
# Validate counts match
|
|
if [ "$DB_ENGINES" -eq "$SQL_ENGINES" ] && [ "$DB_TRANS" -eq "$SQL_TRANS" ] && [ "$DB_VEHICLES" -eq "$SQL_VEHICLES" ]; then
|
|
echo "Validation PASSED - All counts match!"
|
|
exit 0
|
|
else
|
|
echo "Validation FAILED - Counts do not match!"
|
|
exit 1
|
|
fi
|