From 4468c2babaec2532139ad05cb3eb79bf9730f068 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Thu, 9 Apr 2026 07:59:25 +0900 Subject: [PATCH] =?UTF-8?q?fix(database):=20=EB=A7=88=EC=9D=B4=EA=B7=B8?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=85=98=20=EC=8B=A4=ED=96=89=EC=9D=84=20raw?= =?UTF-8?q?=20driver=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 검증 중 발견. 다음 마이그레이션부터는 자동 적용 가능. --- app/core/database.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/core/database.py b/app/core/database.py index 30b4432..e5f2938 100644 --- a/app/core/database.py +++ b/app/core/database.py @@ -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},