m1m02530125 Claude Sonnet 4.6 commited on
Commit
dc43cb2
·
1 Parent(s): 990f9d9

Fix InFailedSqlTransaction by using autocommit for DDL in initialize_db

Browse files
Files changed (1) hide show
  1. db/database.py +7 -0
db/database.py CHANGED
@@ -242,6 +242,10 @@ _MIGRATIONS = [
242
  def initialize_db():
243
  conn = get_connection()
244
 
 
 
 
 
245
  for ddl in _CREATE_TABLES:
246
  conn.execute(ddl)
247
 
@@ -251,6 +255,9 @@ def initialize_db():
251
  except Exception:
252
  pass
253
 
 
 
 
254
  for slot, pos, mn, mx, ml in [
255
  ("breakfast", "hall", 3, 4, 1),
256
  ("breakfast", "kitchen", 3, 3, 1),
 
242
  def initialize_db():
243
  conn = get_connection()
244
 
245
+ # DDL は autocommit で実行(失敗した ALTER TABLE が後続を巻き込まないよう)
246
+ if conn.backend == "postgres":
247
+ conn._conn.autocommit = True
248
+
249
  for ddl in _CREATE_TABLES:
250
  conn.execute(ddl)
251
 
 
255
  except Exception:
256
  pass
257
 
258
+ if conn.backend == "postgres":
259
+ conn._conn.autocommit = False
260
+
261
  for slot, pos, mn, mx, ml in [
262
  ("breakfast", "hall", 3, 4, 1),
263
  ("breakfast", "kitchen", 3, 3, 1),