yet-another-blog/wait-for-db.sh

36 lines
725 B
Bash
Raw Normal View History

#!/bin/bash
# Function to wait for the database to be ready
wait_for_db() {
echo "Waiting for the database to be ready..."
until nc -z db 5432; do
echo "Database is not ready yet. Retrying in 5 seconds..."
sleep 5
done
echo "Database is now ready!"
}
# Function to generate Prisma client
generate_prisma() {
echo "Generating Prisma client..."
npx prisma generate
}
# Function to deploy Prisma migrations
deploy_migrations() {
echo "Deploying Prisma migrations..."
npx prisma migrate deploy
}
# Wait for the database to be ready
wait_for_db
# Generate Prisma client
generate_prisma
# Deploy Prisma migrations
deploy_migrations
# Start the application
echo "Starting the application..."
npm start