Skip to content

Commit 29a6194

Browse files
committed
Repair failed dev Flyway migration before deploy
1 parent 891f71a commit 29a6194

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/deploy-dev.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,36 @@ jobs:
173173
fi
174174
175175
$COMPOSE -f docker-compose.yml -f docker-compose.dev.yml pull
176+
$COMPOSE -f docker-compose.yml -f docker-compose.dev.yml up -d mysql
177+
178+
DB_ROOT_PASSWORD="$(get_env_value MYSQL_ROOT_PASSWORD)"
179+
DB_NAME="$(get_env_value MYSQL_DATABASE)"
180+
181+
for attempt in $(seq 1 30); do
182+
MYSQL_STATUS="$(sudo docker inspect -f '{{.State.Health.Status}}' ontime-dev-mysql 2>/dev/null || true)"
183+
if [ "$MYSQL_STATUS" = "healthy" ]; then
184+
echo "MySQL container is healthy."
185+
break
186+
fi
187+
echo "Waiting for healthy MySQL status; current status: ${MYSQL_STATUS:-unknown}"
188+
sleep 5
189+
done
190+
191+
MYSQL_STATUS="$(sudo docker inspect -f '{{.State.Health.Status}}' ontime-dev-mysql 2>/dev/null || true)"
192+
[ "$MYSQL_STATUS" = "healthy" ] || fail_deploy "MySQL container did not become healthy."
193+
194+
FAILED_V17_COUNT="$(
195+
sudo docker exec ontime-dev-mysql \
196+
mysql -u root --password="$DB_ROOT_PASSWORD" "$DB_NAME" \
197+
-Nse "SELECT COUNT(*) FROM flyway_schema_history WHERE version = '17' AND success = 0;" 2>/dev/null || echo 0
198+
)"
199+
if [ "$FAILED_V17_COUNT" != "0" ]; then
200+
echo "Repairing failed development Flyway migration V17 before backend startup."
201+
sudo docker exec ontime-dev-mysql \
202+
mysql -u root --password="$DB_ROOT_PASSWORD" "$DB_NAME" \
203+
-e "DROP TABLE IF EXISTS user_refresh_token; DELETE FROM flyway_schema_history WHERE version = '17' AND success = 0;"
204+
fi
205+
176206
$COMPOSE -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans
177207
178208
HEALTHY=false

0 commit comments

Comments
 (0)