cacode commited on
Commit
28da773
·
verified ·
1 Parent(s): 3d6b7f2

Upload 67 files

Browse files
app/services/__pycache__/bootstrap.cpython-313.pyc CHANGED
Binary files a/app/services/__pycache__/bootstrap.cpython-313.pyc and b/app/services/__pycache__/bootstrap.cpython-313.pyc differ
 
app/services/bootstrap.py CHANGED
@@ -38,11 +38,11 @@ def submission_indexes() -> tuple[set[str], set[str]]:
38
  return unique_names, index_names
39
 
40
 
41
- def task_columns() -> set[str]:
42
  inspector = inspect(engine)
43
  if "tasks" not in inspector.get_table_names():
44
- return set()
45
- return {column["name"] for column in inspector.get_columns("tasks")}
46
 
47
 
48
  def ensure_submission_constraints() -> None:
@@ -74,12 +74,16 @@ def ensure_submission_constraints() -> None:
74
 
75
 
76
  def migrate_task_media_to_files() -> None:
77
- columns = task_columns()
78
- if not columns:
79
  return
80
 
81
- has_image_data = "image_data" in columns
82
- has_clue_image_data = "clue_image_data" in columns
 
 
 
 
83
  if not has_image_data and not has_clue_image_data:
84
  return
85
 
@@ -116,7 +120,7 @@ def migrate_task_media_to_files() -> None:
116
  )
117
  updates.append("image_path = :image_path")
118
  params["image_path"] = image_path
119
- if has_image_data:
120
  updates.append("image_data = NULL")
121
 
122
  current_clue_path = row.get("clue_image_path")
@@ -131,7 +135,7 @@ def migrate_task_media_to_files() -> None:
131
  )
132
  updates.append("clue_image_path = :clue_image_path")
133
  params["clue_image_path"] = clue_image_path
134
- if has_clue_image_data:
135
  updates.append("clue_image_data = NULL")
136
 
137
  if updates:
@@ -223,3 +227,7 @@ def seed_super_admin(db: Session) -> None:
223
  db.add(admin)
224
  db.commit()
225
 
 
 
 
 
 
38
  return unique_names, index_names
39
 
40
 
41
+ def task_column_details() -> dict[str, dict]:
42
  inspector = inspect(engine)
43
  if "tasks" not in inspector.get_table_names():
44
+ return {}
45
+ return {column["name"]: column for column in inspector.get_columns("tasks")}
46
 
47
 
48
  def ensure_submission_constraints() -> None:
 
74
 
75
 
76
  def migrate_task_media_to_files() -> None:
77
+ column_details = task_column_details()
78
+ if not column_details:
79
  return
80
 
81
+ has_image_data = "image_data" in column_details
82
+ has_clue_image_data = "clue_image_data" in column_details
83
+ can_clear_image_data = bool(has_image_data and column_details["image_data"].get("nullable", True))
84
+ can_clear_clue_image_data = bool(
85
+ has_clue_image_data and column_details["clue_image_data"].get("nullable", True)
86
+ )
87
  if not has_image_data and not has_clue_image_data:
88
  return
89
 
 
120
  )
121
  updates.append("image_path = :image_path")
122
  params["image_path"] = image_path
123
+ if can_clear_image_data:
124
  updates.append("image_data = NULL")
125
 
126
  current_clue_path = row.get("clue_image_path")
 
135
  )
136
  updates.append("clue_image_path = :clue_image_path")
137
  params["clue_image_path"] = clue_image_path
138
+ if can_clear_clue_image_data:
139
  updates.append("clue_image_data = NULL")
140
 
141
  if updates:
 
227
  db.add(admin)
228
  db.commit()
229
 
230
+
231
+
232
+
233
+