фикс импорта бд

This commit is contained in:
2026-04-02 22:52:48 +04:00
parent b608754d36
commit c9b1100e3a
+16 -3
View File
@@ -37,15 +37,28 @@ EOF
log() { printf '[db-import] %s\n' "$*"; } log() { printf '[db-import] %s\n' "$*"; }
die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
require_running_db() { require_ready_db() {
if ! docker compose ps --status running --services 2>/dev/null | grep -qx 'ac-database'; then if ! docker compose ps --status running --services 2>/dev/null | grep -qx 'ac-database'; then
die "ac-database is not running. Start it with: docker compose up -d ac-database" die "ac-database is not running. Start it with: docker compose up -d ac-database"
fi fi
log "waiting for MySQL to be ready..."
local attempts=0
until docker compose exec -T ac-database bash -lc \
"mysql -h 127.0.0.1 -uroot -p\"\$MYSQL_ROOT_PASSWORD\" -e 'SELECT 1;'" \
>/dev/null 2>&1; do
attempts=$((attempts + 1))
if [[ $attempts -ge 30 ]]; then
die "MySQL did not become ready in time. Check: docker logs ac-database"
fi
sleep 2
done
log "MySQL is ready"
} }
mysql_exec() { mysql_exec() {
docker compose exec -T ac-database bash -lc \ docker compose exec -T ac-database bash -lc \
"mysql -uroot -p\"\$MYSQL_ROOT_PASSWORD\"" "mysql -h 127.0.0.1 -uroot -p\"\$MYSQL_ROOT_PASSWORD\""
} }
# ── argument parsing ────────────────────────────────────────────────────────── # ── argument parsing ──────────────────────────────────────────────────────────
@@ -89,7 +102,7 @@ fi
# ── import ──────────────────────────────────────────────────────────────────── # ── import ────────────────────────────────────────────────────────────────────
require_running_db require_ready_db
log "restoring $DUMP_FILE into ac-database..." log "restoring $DUMP_FILE into ac-database..."
log "this may take several minutes..." log "this may take several minutes..."