Files
AudiOhm/backend/fix_source_column.py
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

64 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Fix the source column type bug in listening_history table."""
import asyncio
import sys
from pathlib import Path
# Add backend to path
sys.path.insert(0, str(Path(__file__).parent))
from app.core.database import get_db
from sqlalchemy import text
async def fix_source_column():
"""Fix the source column type from INTEGER to VARCHAR."""
print("🔧 Fixing source column type...")
async for db in get_db():
try:
# Check current type
result = await db.execute(text("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'listening_history'
AND column_name = 'source'
"""))
for row in result:
print(f" Current type: {row[1]}")
# Fix the column type
await db.execute(text("""
ALTER TABLE listening_history
ALTER COLUMN source
TYPE VARCHAR(50)
USING CASE WHEN source IS NOT NULL THEN 'library' ELSE NULL END
"""))
await db.commit()
print(" ✅ Column type fixed: INTEGER → VARCHAR(50)")
# Verify the fix
result = await db.execute(text("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'listening_history'
AND column_name = 'source'
"""))
for row in result:
print(f" ✅ New type: {row[1]}")
except Exception as e:
print(f" ❌ Error: {e}")
await db.rollback()
raise
finally:
await db.close()
print("🎉 Source column fixed successfully!")
if __name__ == "__main__":
asyncio.run(fix_source_column())