fix: improve database permissions script with enhanced logging and user feedback
- Added detailed logging to track changes and errors in the database permissions script. - Implemented user feedback prompts to enhance usability and inform users of script progress. - Strengthened error handling for ownership changes to ensure robustness.
This commit is contained in:
119
scripts/fix-i18n-sql.sh
Executable file
119
scripts/fix-i18n-sql.sh
Executable file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
# Direkter SQL-Fix für i18n-Daten in SQLite
|
||||
# Konvertiert String-Werte zu JSON-Format
|
||||
|
||||
set -e
|
||||
|
||||
DB_PATH="./data/prod.db"
|
||||
BACKUP_PATH="./data/prod.db.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
if [ ! -f "$DB_PATH" ]; then
|
||||
echo "❌ Datenbank nicht gefunden: $DB_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🔧 Fixe i18n-Daten in SQLite-Datenbank..."
|
||||
echo ""
|
||||
|
||||
# Backup erstellen
|
||||
echo "💾 Erstelle Backup..."
|
||||
cp "$DB_PATH" "$BACKUP_PATH"
|
||||
echo "✅ Backup erstellt: $BACKUP_PATH"
|
||||
echo ""
|
||||
|
||||
# Prüfe ob sqlite3 verfügbar ist
|
||||
if ! command -v sqlite3 &> /dev/null; then
|
||||
echo "⚠️ sqlite3 nicht gefunden. Versuche im Container..."
|
||||
|
||||
# Führe SQL-Befehle im Container aus
|
||||
docker exec hoerdle sh << 'EOF'
|
||||
# SQL-Befehle
|
||||
sqlite3 /app/data/prod.db << 'SQL'
|
||||
-- Backup erstellen
|
||||
.backup /app/data/prod.db.backup
|
||||
|
||||
-- Fix Genre.name
|
||||
UPDATE Genre
|
||||
SET name = json_object('de', name, 'en', name)
|
||||
WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
|
||||
|
||||
-- Fix Genre.subtitle
|
||||
UPDATE Genre
|
||||
SET subtitle = json_object('de', subtitle, 'en', subtitle)
|
||||
WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
|
||||
|
||||
-- Fix Special.name
|
||||
UPDATE Special
|
||||
SET name = json_object('de', name, 'en', name)
|
||||
WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
|
||||
|
||||
-- Fix Special.subtitle
|
||||
UPDATE Special
|
||||
SET subtitle = json_object('de', subtitle, 'en', subtitle)
|
||||
WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
|
||||
|
||||
-- Fix News.title
|
||||
UPDATE News
|
||||
SET title = json_object('de', title, 'en', title)
|
||||
WHERE typeof(title) = 'text' AND title NOT LIKE '{%';
|
||||
|
||||
-- Fix News.content
|
||||
UPDATE News
|
||||
SET content = json_object('de', content, 'en', content)
|
||||
WHERE typeof(content) = 'text' AND content NOT LIKE '{%';
|
||||
|
||||
-- Zeige Änderungen
|
||||
SELECT 'Genre.name gefixt:' as status, COUNT(*) as count
|
||||
FROM Genre WHERE typeof(name) = 'text' AND name LIKE '{%';
|
||||
SQL
|
||||
EOF
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ i18n-Daten wurden erfolgreich gefixt!"
|
||||
else
|
||||
echo "❌ Fehler beim Ausführen der SQL-Befehle"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Führe direkt auf dem Host aus
|
||||
sqlite3 "$DB_PATH" << 'SQL'
|
||||
-- Fix Genre.name
|
||||
UPDATE Genre
|
||||
SET name = json_object('de', name, 'en', name)
|
||||
WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
|
||||
|
||||
-- Fix Genre.subtitle
|
||||
UPDATE Genre
|
||||
SET subtitle = json_object('de', subtitle, 'en', subtitle)
|
||||
WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
|
||||
|
||||
-- Fix Special.name
|
||||
UPDATE Special
|
||||
SET name = json_object('de', name, 'en', name)
|
||||
WHERE typeof(name) = 'text' AND name NOT LIKE '{%';
|
||||
|
||||
-- Fix Special.subtitle
|
||||
UPDATE Special
|
||||
SET subtitle = json_object('de', subtitle, 'en', subtitle)
|
||||
WHERE subtitle IS NOT NULL AND typeof(subtitle) = 'text' AND subtitle NOT LIKE '{%';
|
||||
|
||||
-- Fix News.title
|
||||
UPDATE News
|
||||
SET title = json_object('de', title, 'en', title)
|
||||
WHERE typeof(title) = 'text' AND title NOT LIKE '{%';
|
||||
|
||||
-- Fix News.content
|
||||
UPDATE News
|
||||
SET content = json_object('de', content, 'en', content)
|
||||
WHERE typeof(content) = 'text' AND content NOT LIKE '{%';
|
||||
|
||||
SELECT 'Fertig!' as status;
|
||||
SQL
|
||||
|
||||
echo "✅ i18n-Daten wurden erfolgreich gefixt!"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "🔄 Bitte starte den Container neu:"
|
||||
echo " docker compose restart hoerdle"
|
||||
|
||||
Reference in New Issue
Block a user