33 lines
1011 B
Bash
Executable File
33 lines
1011 B
Bash
Executable File
set -euo pipefail
|
|
FILE="services/auth/src/app/schemas/user.py"
|
|
[ -f "$FILE" ] || { echo "Not found: $FILE"; exit 1; }
|
|
|
|
python3 - "$FILE" <<'PY'
|
|
from pathlib import Path
|
|
import re, sys
|
|
p = Path(sys.argv[1]); s = p.read_text()
|
|
|
|
if "from uuid import UUID" not in s:
|
|
s = "from uuid import UUID\n" + s
|
|
|
|
s = re.sub(r'(\bid\s*:\s*)str', r'\1UUID', s)
|
|
s = re.sub(r'(\buser_id\s*:\s*)str', r'\1UUID', s)
|
|
|
|
# Включаем from_attributes (pydantic v2) или orm_mode (v1) для моделей ответа
|
|
if "model_config" not in s and "orm_mode" not in s:
|
|
s = re.sub(
|
|
r"class\s+\w+Out\s*\((?:.|\n)*?\):",
|
|
lambda m: m.group(0) +
|
|
"\n try:\n from pydantic import ConfigDict\n model_config = ConfigDict(from_attributes=True)\n"
|
|
" except Exception:\n class Config:\n orm_mode = True\n",
|
|
s
|
|
)
|
|
|
|
p.write_text(s)
|
|
print("[auth] Patched:", p)
|
|
PY
|
|
|
|
echo "[auth] Rebuild & restart…"
|
|
docker compose build auth
|
|
docker compose restart auth
|