Skip to content

Commit c125138

Browse files
committed
fix: handle missing Alembic configuration gracefully in deploy.sh
- Skip migrations if Alembic is not configured (no script_location error) - Database schema will be created on application startup via SQLAlchemy - Real migration errors still cause deployment to fail - Add proper database readiness check before attempting migrations
1 parent ded76d6 commit c125138

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

scripts/deploy.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,38 @@ run_migrations() {
197197

198198
cd "$DEPLOY_DIR"
199199

200-
# Run migrations
201-
docker compose -f "$COMPOSE_FILE" --profile migrate run --rm migrate || die "Database migration failed"
200+
# Ensure database is running and healthy
201+
docker compose -f "$COMPOSE_FILE" up -d db
202202

203-
log INFO "Migrations completed successfully"
203+
local retries=30
204+
while [ $retries -gt 0 ]; do
205+
if docker compose -f "$COMPOSE_FILE" exec -T db pg_isready -U syfthub -d syfthub &>/dev/null; then
206+
break
207+
fi
208+
log INFO "Waiting for database to be ready... ($retries retries left)"
209+
sleep 2
210+
retries=$((retries - 1))
211+
done
212+
213+
if [ $retries -eq 0 ]; then
214+
die "Database failed to become ready"
215+
fi
216+
217+
# Try to run migrations - handle case where Alembic isn't configured
218+
local migration_output
219+
if migration_output=$(docker compose -f "$COMPOSE_FILE" --profile migrate run --rm migrate 2>&1); then
220+
log INFO "Migrations completed successfully"
221+
else
222+
# Check if the error is because Alembic isn't configured
223+
if echo "$migration_output" | grep -q "No 'script_location' key found\|No such file or directory.*alembic"; then
224+
log WARN "Alembic not configured - skipping migrations"
225+
log INFO "Database schema will be created on application startup"
226+
else
227+
# Real migration error - fail the deployment
228+
echo "$migration_output"
229+
die "Database migration failed"
230+
fi
231+
fi
204232
}
205233

206234
# =============================================================================

0 commit comments

Comments
 (0)