SOY NV AI commited on
Commit
6ceb644
ยท
1 Parent(s): ee3d060

Update migrations.py: add role_analysis unique constraint removal logic

Browse files
Files changed (1) hide show
  1. 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: