improve db script
This commit is contained in:
parent
18934e8862
commit
214528ed76
35
deploy-db.sh
35
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 "=================================="
|
||||
|
Loading…
x
Reference in New Issue
Block a user