mirror of
https://github.com/wahyd4/you-music.git
synced 2026-08-09 05:06:44 +10:00
43 lines
1.2 KiB
Bash
Executable File
43 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script to enable WAL mode on existing SQLite database
|
|
# This improves concurrent access and reduces lock contention
|
|
|
|
set -e
|
|
|
|
echo "🔧 Enabling WAL mode for SQLite database..."
|
|
|
|
# Get database path from environment or use default
|
|
DB_PATH="${DATABASE_URL:-sqlite+aiosqlite:///./data/youmusic.db}"
|
|
# Extract file path from SQLite URL
|
|
DB_FILE=$(echo "$DB_PATH" | sed 's|sqlite+aiosqlite://||' | sed 's|sqlite://||')
|
|
|
|
# Handle relative paths
|
|
if [[ "$DB_FILE" == ./* ]]; then
|
|
DB_FILE="/app/data/youmusic.db"
|
|
fi
|
|
|
|
echo "📁 Database file: $DB_FILE"
|
|
|
|
# Check if database exists
|
|
if [ ! -f "$DB_FILE" ]; then
|
|
echo "⚠️ Database file not found: $DB_FILE"
|
|
echo " This is normal for new installations - WAL will be enabled on first run"
|
|
exit 0
|
|
fi
|
|
|
|
# Enable WAL mode using sqlite3
|
|
echo "🔄 Enabling WAL mode..."
|
|
sqlite3 "$DB_FILE" "PRAGMA journal_mode=WAL;"
|
|
sqlite3 "$DB_FILE" "PRAGMA synchronous=NORMAL;"
|
|
sqlite3 "$DB_FILE" "PRAGMA busy_timeout=30000;"
|
|
|
|
# Verify WAL mode is enabled
|
|
JOURNAL_MODE=$(sqlite3 "$DB_FILE" "PRAGMA journal_mode;")
|
|
echo "✅ Journal mode: $JOURNAL_MODE"
|
|
|
|
if [ "$JOURNAL_MODE" = "wal" ]; then
|
|
echo "✅ WAL mode successfully enabled!"
|
|
else
|
|
echo "⚠️ Warning: Journal mode is $JOURNAL_MODE, expected 'wal'"
|
|
fi
|