Files
AudiOhm/backend/fix_bug_1.sh
T
root 801e6a050b prod: UI Optimisée mise en production
- Documentation archivée et réorganisée
- Backend: Ajout tests, migrations, library service, rate limiting
- Frontend: Suppression Flutter, focus sur interface web HTML/JS
- Tailwind CSS ajouté pour le style
- Améliorations UX et corrections bugs

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-20 09:56:39 +00:00

127 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Fix Bug #1: Type mismatch for listening_history.completed column
# This script fixes the INTEGER -> BOOLEAN type mismatch
echo "================================================"
echo "AudiOhm - Bug #1 Fix Script"
echo "================================================"
echo ""
echo "This will fix the type mismatch in listening_history.completed"
echo ""
# Check if running as root or with sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo"
exit 1
fi
# Database connection details
DB_HOST="${DB_HOST:-localhost}"
DB_PORT="${DB_PORT:-5432}"
DB_NAME="${DB_NAME:-audiOhm}"
DB_USER="${DB_USER:-audiOhm}"
DB_PASS="${DB_PASS:-audiOhm}"
echo "Database: $DB_NAME on $DB_HOST:$DB_PORT"
echo ""
# Check if psql is available
if ! command -v psql &> /dev/null; then
echo "Error: psql is not installed"
echo "Install it with: apt-get install postgresql-client"
exit 1
fi
echo "Step 1: Checking current column type..."
echo ""
CURRENT_TYPE=$(PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER -d $DB_NAME -t -c \
"SELECT data_type FROM information_schema.columns WHERE table_name = 'listening_history' AND column_name = 'completed';" 2>&1)
if [ $? -ne 0 ]; then
echo "Error: Could not connect to database"
echo "Please check your database connection settings"
exit 1
fi
CURRENT_TYPE=$(echo $CURRENT_TYPE | xargs)
echo "Current type: $CURRENT_TYPE"
echo ""
if [ "$CURRENT_TYPE" = "boolean" ]; then
echo "✓ Column is already BOOLEAN - no fix needed!"
exit 0
fi
if [ "$CURRENT_TYPE" != "integer" ]; then
echo "⚠ Warning: Unexpected type '$CURRENT_TYPE'"
echo "Please verify manually"
exit 1
fi
echo "Step 2: Creating backup..."
echo ""
BACKUP_FILE="audiOhm_backup_$(date +%Y%m%d_%H%M%S).sql"
PGPASSWORD=$DB_PASS pg_dump -h $DB_HOST -U $DB_USER $DB_NAME > $BACKUP_FILE 2>&1
if [ $? -eq 0 ]; then
echo "✓ Backup created: $BACKUP_FILE"
else
echo "✗ Backup failed - aborting"
exit 1
fi
echo ""
echo "Step 3: Fixing column type..."
echo ""
SQL="
-- Convert integer to boolean
ALTER TABLE listening_history
ALTER COLUMN completed TYPE BOOLEAN USING completed::BOOLEAN;
"
echo "$SQL" | PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER -d $DB_NAME 2>&1
if [ $? -eq 0 ]; then
echo "✓ Column type fixed successfully"
else
echo "✗ Fix failed - restoring backup"
PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER $DB_NAME < $BACKUP_FILE 2>&1
echo "✓ Backup restored"
exit 1
fi
echo ""
echo "Step 4: Verifying fix..."
echo ""
NEW_TYPE=$(PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER -d $DB_NAME -t -c \
"SELECT data_type FROM information_schema.columns WHERE table_name = 'listening_history' AND column_name = 'completed';" 2>&1)
NEW_TYPE=$(echo $NEW_TYPE | xargs)
echo "New type: $NEW_TYPE"
echo ""
if [ "$NEW_TYPE" = "boolean" ]; then
echo "================================================"
echo "✓✓✓ SUCCESS! Bug #1 is now FIXED ✓✓✓"
echo "================================================"
echo ""
echo "What was fixed:"
echo " - listening_history.completed: INTEGER -> BOOLEAN"
echo ""
echo "Next steps:"
echo " 1. Restart the backend server"
echo " 2. Run the tests again: python3 test_new_features.py"
echo ""
echo "Backup saved as: $BACKUP_FILE"
exit 0
else
echo "✗ Verification failed - type is still $NEW_TYPE"
exit 1
fi