fix: 修复本地与 Docker 启动脚本的数据库鉴权、端口冲突与镜像构建问题

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-30 09:12:59 +08:00
co-authored by Cursor
parent 2fba42c9fd
commit 3bccd89028
9 changed files with 102 additions and 11 deletions
+31
View File
@@ -491,6 +491,37 @@ def wait_port(host: str, port: int, timeout: int = 60) -> bool:
return False
def wait_db_auth(
host: str, port, user: str, password: str, timeout: int = 90
) -> bool:
"""等待 MySQL 真正"可鉴权"就绪(而非仅 TCP 端口可达)。
冷启动/首次初始化数据卷时,端口可能先于用户与权限子系统就绪,
导致 Prisma 报 P1000 鉴权失败。这里用真实账号反复尝试登录,直到成功或超时。"""
try:
import pymysql
except ImportError:
# 没有 pymysql 时退化为不阻塞(交由后续命令报错),但给出提示
print("[artveris] 未安装 pymysql,跳过鉴权就绪等待(可能出现 P1000)。")
return True
print(f"[artveris] 等待 MySQL 鉴权就绪 {host}:{port} …")
start = time.time()
last_err: Exception | None = None
while time.time() - start < timeout:
try:
conn = pymysql.connect(
host=host, port=int(port), user=user, password=password,
connect_timeout=3, charset="utf8mb4",
)
conn.close()
print("[artveris] MySQL 鉴权就绪")
return True
except Exception as e: # noqa: BLE001
last_err = e
time.sleep(2)
print(f"[artveris] 等待 MySQL 鉴权超时:{last_err}")
return False
def ensure_mysql_database(
host: str, port, user: str, password: str, db_name: str
) -> bool: