fix(database): 마이그레이션 실행을 raw driver 로 변경
text(sql) 은 SQLAlchemy 가 :name 패턴을 named bind parameter 로 해석하므로 SQL 주석이나 literal 안에 콜론이 들어가면 InvalidRequestError 발생. ai_summary[:200] 같은 표기가 들어간 101_global_digests.sql 적용 시 fastapi startup 자체가 떨어지는 문제가 발생. exec_driver_sql 은 SQL 을 driver(asyncpg) 에 그대로 전달하므로 콜론 escape 불요. schema_migrations INSERT 만 named bind 가 필요하므로 그건 그대로 유지. Phase 4 deploy 검증 중 발견. 다음 마이그레이션부터는 자동 적용 가능.
This commit is contained in:
@@ -115,7 +115,10 @@ async def _run_migrations(conn) -> None:
|
||||
sql = path.read_text(encoding="utf-8")
|
||||
_validate_sql_content(name, sql)
|
||||
logger.info(f"[migration] {name} 실행 중...")
|
||||
await conn.execute(text(sql))
|
||||
# raw driver SQL 사용 — text() 의 :name bind parameter 해석으로
|
||||
# SQL 주석/literal 에 콜론이 들어가면 InvalidRequestError 발생.
|
||||
# exec_driver_sql 은 SQL 을 driver(asyncpg) 에 그대로 전달.
|
||||
await conn.exec_driver_sql(sql)
|
||||
await conn.execute(
|
||||
text("INSERT INTO schema_migrations (version, name) VALUES (:v, :n)"),
|
||||
{"v": version, "n": name},
|
||||
|
||||
Reference in New Issue
Block a user