From 214528ed763da54e2fc262acb0e296d70061da7f Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Tue, 10 Jun 2025 20:54:00 -0300 Subject: [PATCH] improve db script --- deploy-db.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/deploy-db.sh b/deploy-db.sh index e650eaa..5c42cc2 100755 --- a/deploy-db.sh +++ b/deploy-db.sh @@ -9,7 +9,8 @@ set -e # Exit on any error DB_CONTAINER="opencand_db" DB_NAME="opencand" DB_USER="root" -SQL_FILE="./db/db.sql" +SQL_URL="https://git.ivanch.me/ivanch/opencand/raw/branch/main/db/db.sql" +SQL_FILE="./db.sql" # Colors for output RED='\033[0;31m' @@ -33,16 +34,37 @@ if ! docker ps --format "table {{.Names}}" | grep -q "^${DB_CONTAINER}$"; then exit 1 fi -# Check if SQL file exists +# Download the SQL file +echo -e "${YELLOW}๐Ÿ“ฅ Downloading SQL file...${NC}" +if command -v curl &> /dev/null; then + if curl -L -o "$SQL_FILE" "$SQL_URL"; then + echo "โœ… SQL file downloaded successfully" + else + echo -e "${RED}โŒ Error: Failed to download SQL file from ${SQL_URL}${NC}" + exit 1 + fi +elif command -v wget &> /dev/null; then + if wget -O "$SQL_FILE" "$SQL_URL"; then + echo "โœ… SQL file downloaded successfully" + else + echo -e "${RED}โŒ Error: Failed to download SQL file from ${SQL_URL}${NC}" + exit 1 + fi +else + echo -e "${RED}โŒ Error: Neither curl nor wget is available for downloading${NC}" + exit 1 +fi + +# Check if SQL file exists (after download) if [ ! -f "$SQL_FILE" ]; then - echo -e "${RED}โŒ Error: SQL file '${SQL_FILE}' not found${NC}" + echo -e "${RED}โŒ Error: SQL file '${SQL_FILE}' not found after download${NC}" exit 1 fi echo -e "${YELLOW}๐Ÿ“‹ Pre-deployment checks:${NC}" echo "โœ… Docker is running" echo "โœ… Database container is running" -echo "โœ… SQL file exists" +echo "โœ… SQL file downloaded" echo "" # Wait for database to be ready @@ -86,6 +108,11 @@ else exit 1 fi +# Clean up downloaded SQL file +echo -e "${YELLOW}๐Ÿงน Cleaning up...${NC}" +rm -f "$SQL_FILE" +echo "โœ… Temporary SQL file removed" + echo "" echo -e "${GREEN}๐ŸŽ‰ Deployment completed successfully!${NC}" echo "=================================="