49 lines
1.5 KiB
Bash
49 lines
1.5 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "🚀 Starting Oltalama application..."
|
|
|
|
# Ensure database directory exists
|
|
mkdir -p database
|
|
|
|
# Run database migrations
|
|
echo "📊 Running database migrations..."
|
|
if node migrations/run-migrations.js; then
|
|
echo "✅ Migrations completed successfully"
|
|
else
|
|
echo "⚠️ Migration failed, but continuing..."
|
|
fi
|
|
|
|
# Check if we should seed the database
|
|
# Only seed if database is empty (no admin users)
|
|
if [ ! -f "database/oltalama.db" ] || [ ! -s "database/oltalama.db" ]; then
|
|
echo "🌱 Database is empty, seeding initial data..."
|
|
if node seeders/run-seeders.js; then
|
|
echo "✅ Seeding completed successfully"
|
|
else
|
|
echo "⚠️ Seeding failed, but continuing..."
|
|
fi
|
|
else
|
|
# Check if admin user exists
|
|
if command -v sqlite3 >/dev/null 2>&1; then
|
|
ADMIN_COUNT=$(sqlite3 database/oltalama.db "SELECT COUNT(*) FROM admin_user;" 2>/dev/null || echo "0")
|
|
if [ "$ADMIN_COUNT" = "0" ]; then
|
|
echo "🌱 Database exists but no admin user found. Running seeders..."
|
|
if node seeders/run-seeders.js; then
|
|
echo "✅ Seeding completed successfully"
|
|
else
|
|
echo "⚠️ Seeding failed, but continuing..."
|
|
fi
|
|
else
|
|
echo "✅ Database already initialized with admin user(s), skipping seeders."
|
|
fi
|
|
else
|
|
echo "⚠️ sqlite3 command not found, skipping admin user check."
|
|
fi
|
|
fi
|
|
|
|
# Start the application
|
|
echo "✨ Starting server..."
|
|
exec "$@"
|
|
|