Files
hoerdle/FIX_I18N.md
Hördle Bot a503edb220 fix: enhance database script with improved permission handling and error checks
- Added permission setting for backup and temporary database files to ensure proper access.
- Implemented checks for file readability and ownership adjustments to enhance robustness.
- Included detailed SQL commands to fix internationalization data in the database, improving data integrity.
2025-12-01 17:06:07 +01:00

84 lines
2.5 KiB
Markdown

# Fix für i18n-Daten (String → JSON Konvertierung)
## Problem
Die Datenbank hat Genre-/Special-/News-Namen als einfache Strings (`"Rock"`) statt JSON (`{"de": "Rock", "en": "Rock"}`) gespeichert, was zu `SyntaxError: "Rock" is not valid JSON` führt.
## Lösung: Manuell ausführen
Führe diese Befehle **direkt auf dem Server** aus:
```bash
cd ~/hoerdle
# 1. Backup erstellen
docker cp hoerdle:/app/data/prod.db ./data/prod.db.backup.$(date +%Y%m%d_%H%M%S)
# 2. Kopiere DB lokal
docker cp hoerdle:/app/data/prod.db ./data/prod.db.tmp
# 3. Setze Berechtigungen
sudo chmod 666 ./data/prod.db.tmp
sudo chmod 775 ./data
# 4. Prüfe ob sqlite3 installiert ist
which sqlite3 || sudo apt-get install -y sqlite3
# 5. Fixe die Datenbank (kopiere diesen Block komplett)
sqlite3 ./data/prod.db.tmp << 'EOF'
UPDATE Genre SET name = json_object('de', name, 'en', name) WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
UPDATE Genre SET subtitle = json_object('de', subtitle, 'en', subtitle) WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
UPDATE Special SET name = json_object('de', name, 'en', name) WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
UPDATE Special SET subtitle = json_object('de', subtitle, 'en', subtitle) WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
UPDATE News SET title = json_object('de', title, 'en', title) WHERE typeof(title) = 'text' AND title NOT LIKE '{%';
UPDATE News SET content = json_object('de', content, 'en', content) WHERE typeof(content) = 'text' AND content NOT LIKE '{%';
SELECT '✅ Fertig!' as status;
EOF
# 6. Kopiere zurück
docker cp ./data/prod.db.tmp hoerdle:/app/data/prod.db
# 7. Aufräumen
rm ./data/prod.db.tmp
# 8. Container neu starten
docker compose restart hoerdle
# 9. Logs prüfen
docker logs hoerdle --tail=50
```
Falls Schritt 5 mit "permission denied" fehlschlägt, verwende `sudo`:
```bash
sudo sqlite3 ./data/prod.db.tmp << 'EOF'
[... SQL-Befehle wie oben ...]
EOF
```
## Automatisiertes Skript
Alternativ kannst du das automatische Skript verwenden:
```bash
./scripts/fix-i18n-easy.sh
```
Oder das lokale Skript:
```bash
./scripts/fix-i18n-local.sh
```
## Prüfen ob es funktioniert hat
Nach dem Neustart sollte die Seite wieder funktionieren:
```bash
# Prüfe Logs (sollte keine JSON-Fehler mehr zeigen)
docker logs hoerdle --tail=100 | grep -i "json\|error" || echo "✅ Keine JSON-Fehler gefunden"
# Teste die Seite
curl -s https://hoerdle.de/de | head -20
```