SOY NV AI commited on
Commit ยท
6ceb644
1
Parent(s): ee3d060
Update migrations.py: add role_analysis unique constraint removal logic
Browse files- app/migrations.py +32 -0
app/migrations.py
CHANGED
|
@@ -318,6 +318,38 @@ def check_and_migrate_db(app):
|
|
| 318 |
except Exception as e:
|
| 319 |
logger.error(f"merged_image_path ์ปฌ๋ผ ์ถ๊ฐ ์คํจ: {e}")
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
logger.info("๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
์๋ฃ")
|
| 322 |
|
| 323 |
except Exception as e:
|
|
|
|
| 318 |
except Exception as e:
|
| 319 |
logger.error(f"merged_image_path ์ปฌ๋ผ ์ถ๊ฐ ์คํจ: {e}")
|
| 320 |
|
| 321 |
+
# 14. role_analysis ํ
์ด๋ธ์ ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด ์ ๊ฑฐ
|
| 322 |
+
# ๊ฐ์ file_id, role_prompt_id ์กฐํฉ์ผ๋ก ์ฌ๋ฌ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ ์ ์๋๋ก ํจ
|
| 323 |
+
if 'role_analysis' in table_names:
|
| 324 |
+
logger.info("role_analysis ํ
์ด๋ธ ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด ํ์ธ ์ค...")
|
| 325 |
+
try:
|
| 326 |
+
if engine.dialect.name == 'postgresql':
|
| 327 |
+
# PostgreSQL: information_schema์์ ์ ์ฝ์กฐ๊ฑด ํ์ธ
|
| 328 |
+
result = conn.execute(text("""
|
| 329 |
+
SELECT constraint_name
|
| 330 |
+
FROM information_schema.table_constraints
|
| 331 |
+
WHERE table_name = 'role_analysis'
|
| 332 |
+
AND constraint_type = 'UNIQUE'
|
| 333 |
+
"""))
|
| 334 |
+
constraints = [row[0] for row in result.fetchall()]
|
| 335 |
+
|
| 336 |
+
if constraints:
|
| 337 |
+
logger.info(f"role_analysis ํ
์ด๋ธ์์ ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด ์ ๊ฑฐ ์ค: {constraints}")
|
| 338 |
+
for constraint_name in constraints:
|
| 339 |
+
try:
|
| 340 |
+
conn.execute(text(f'ALTER TABLE role_analysis DROP CONSTRAINT IF EXISTS "{constraint_name}"'))
|
| 341 |
+
logger.info(f"'{constraint_name}' ์ ์ฝ์กฐ๊ฑด ์ ๊ฑฐ ์๋ฃ")
|
| 342 |
+
except Exception as e:
|
| 343 |
+
logger.warning(f"'{constraint_name}' ์ ๊ฑฐ ์คํจ (๋ฌด์): {e}")
|
| 344 |
+
conn.commit()
|
| 345 |
+
else:
|
| 346 |
+
logger.info("role_analysis ํ
์ด๋ธ์ ์ ๊ฑฐํ ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด์ด ์์ต๋๋ค.")
|
| 347 |
+
else:
|
| 348 |
+
# SQLite๋ ์ ์ฝ์กฐ๊ฑด ์ง์ ์ ๊ฑฐ ๋ถ๊ฐ - ์ฑ ์์ ์์๋ ๊ฑด๋๋ฐ๊ณ ๋ณ๋ ๋ง์ด๊ทธ๋ ์ด์
์คํฌ๋ฆฝํธ ์ฌ์ฉ
|
| 349 |
+
logger.info("SQLite: role_analysis ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด์ ๋ณ๋ ๋ง์ด๊ทธ๋ ์ด์
์คํฌ๋ฆฝํธ๋ก ์ฒ๋ฆฌ๋ฉ๋๋ค.")
|
| 350 |
+
except Exception as e:
|
| 351 |
+
logger.warning(f"role_analysis ์ ๋ํฌ ์ ์ฝ์กฐ๊ฑด ํ์ธ/์ ๊ฑฐ ์ค ์ค๋ฅ (๋ฌด์ ๊ฐ๋ฅ): {e}")
|
| 352 |
+
|
| 353 |
logger.info("๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
์๋ฃ")
|
| 354 |
|
| 355 |
except Exception as e:
|