From 1ee9af8f280f3b1ec58ac2d108106e54bf844abb Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Mon, 20 Oct 2025 12:55:56 +0200 Subject: [PATCH] deployment fix? --- deploy.sh | 18 ++---------------- docker-compose.yml | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/deploy.sh b/deploy.sh index 6af684b..bd5b2d8 100755 --- a/deploy.sh +++ b/deploy.sh @@ -57,22 +57,8 @@ fi # Apply database migrations echo -e "${YELLOW}🗄️ Applying database migrations...${NC}" -if [ -f "backend/create_backup_jobs_table.sql" ]; then - echo "Applying backup_jobs table migration..." - - # Get list of databases - DATABASES=$(docker-compose exec -T postgres psql -U storycove -lqt | cut -d \| -f 1 | grep -E '^ storycove' | sed 's/^[ \t]*//') - - # Apply migration to each database - for DB_NAME in $DATABASES; do - echo " - Applying to database: $DB_NAME" - docker-compose exec -T postgres psql -U storycove -d "$DB_NAME" < backend/create_backup_jobs_table.sql 2>&1 | grep -E "(CREATE|ERROR)" || true - done - - echo -e "${GREEN}✅ Database migrations applied${NC}" -else - echo -e "${YELLOW}⚠️ No migration files found, skipping...${NC}" -fi +docker-compose run --rm migrations +echo -e "${GREEN}✅ Database migrations applied${NC}" # Check if Solr is ready echo -e "${YELLOW}🔍 Checking Solr health...${NC}" diff --git a/docker-compose.yml b/docker-compose.yml index 72f079c..00c374e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,34 +65,40 @@ services: - postgres_data:/var/lib/postgresql/data networks: - storycove-network + healthcheck: + test: ["CMD-SHELL", "pg_isready -U storycove -d storycove"] + interval: 5s + timeout: 5s + retries: 5 migrations: image: postgres:15-alpine depends_on: - - postgres + postgres: + condition: service_healthy volumes: - ./backend/create_backup_jobs_table.sql:/migrations/create_backup_jobs_table.sql:ro networks: - storycove-network + environment: + - PGPASSWORD=${DB_PASSWORD} entrypoint: /bin/sh command: > -c " - echo 'Waiting for postgres to be ready...'; - sleep 5; - echo 'Applying migrations to all databases...'; + echo '🗄️ Applying database migrations...'; for DB in storycove storycove_afterdark storycove_clas storycove_secret; do - echo \"Checking if database \$$DB exists...\"; - if PGPASSWORD=${DB_PASSWORD} psql -h postgres -U storycove -lqt | cut -d \\| -f 1 | grep -qw \$$DB; then - echo \"Applying migration to \$$DB...\"; - PGPASSWORD=${DB_PASSWORD} psql -h postgres -U storycove -d \$$DB -f /migrations/create_backup_jobs_table.sql; - echo \"✓ Migration applied to \$$DB\"; - else - echo \"⚠ Database \$$DB does not exist, skipping...\"; + if psql -h postgres -U storycove -lqt | cut -d '|' -f 1 | grep -qw \$$DB; then + echo \" ✓ Applying migration to \$$DB...\"; + psql -h postgres -U storycove -d \$$DB -f /migrations/create_backup_jobs_table.sql > /dev/null 2>&1 || true; fi; done; - echo 'All migrations complete!'; + echo '✅ Migrations complete!'; + sleep infinity; " - restart: "no" + deploy: + restart_policy: + condition: on-failure + max_attempts: 1 solr: