@@ -60,6 +60,7 @@ def init_db(self):
6060 display_name TEXT,
6161 local_export_path TEXT,
6262 hf_export_path TEXT,
63+ s3_export_path TEXT,
6364 num_questions FLOAT,
6465 total_count FLOAT,
6566 topics TEXT,
@@ -107,6 +108,7 @@ def init_db(self):
107108 display_name TEXT,
108109 local_export_path TEXT,
109110 hf_export_path TEXT,
111+ s3_export_path TEXT,
110112 job_id TEXT,
111113 job_name TEXT UNIQUE,
112114 job_status TEXT,
@@ -145,29 +147,24 @@ def save_generation_metadata(self, metadata: Dict) -> int:
145147 try :
146148 # Prepare data outside transaction
147149 if metadata .get ('generate_file_name' ):
148-
149150 output_paths = metadata .get ('output_path' , {})
150151 else :
151-
152152 output_paths = {}
153-
154-
155153
156154 # Use a single connection with enhanced settings
157155 with self .get_connection () as conn :
158156 conn .execute ("BEGIN IMMEDIATE" )
159157
160-
161158 cursor = conn .cursor ()
162159
163160 query = """
164161 INSERT INTO generation_metadata (
165- timestamp, technique, model_id, inference_type, caii_endpoint, use_case,
166- custom_prompt, model_parameters, input_key, output_key, output_value, generate_file_name,
167- display_name, local_export_path, hf_export_path,
168- num_questions, total_count, topics, examples,
169- schema, doc_paths, input_path, job_id, job_name, job_status, job_creator_name
170- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
162+ timestamp, technique, model_id, inference_type, caii_endpoint, use_case,
163+ custom_prompt, model_parameters, input_key, output_key, output_value, generate_file_name,
164+ display_name, local_export_path, hf_export_path, s3_export_path ,
165+ num_questions, total_count, topics, examples,
166+ schema, doc_paths, input_path, job_id, job_name, job_status, job_creator_name
167+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
171168 """
172169
173170 values = (
@@ -186,6 +183,7 @@ def save_generation_metadata(self, metadata: Dict) -> int:
186183 metadata .get ('display_name' , None ),
187184 output_paths .get ('local' , None ),
188185 output_paths .get ('huggingface' , None ),
186+ output_paths .get ('s3' , None ),
189187 metadata .get ('num_questions' , None ),
190188 metadata .get ('total_count' , None ),
191189 metadata .get ('topics' , None ),
@@ -198,20 +196,18 @@ def save_generation_metadata(self, metadata: Dict) -> int:
198196 metadata .get ('job_status' , None ),
199197 metadata .get ('job_creator_name' , None )
200198 )
201- #print(values)
202199
203200 cursor .execute (query , values )
204201 conn .commit ()
205202 return cursor .lastrowid
206203
207204 except sqlite3 .OperationalError as e :
208- if conn :
205+ if ' conn' in locals () :
209206 conn .rollback ()
210207 print (f"Database operation error in save_generation_metadata: { e } " )
211-
212208 raise
213209 except Exception as e :
214- if conn :
210+ if ' conn' in locals () :
215211 conn .rollback ()
216212 print (f"Error saving metadata to database: { str (e )} " )
217213 raise
@@ -359,7 +355,6 @@ def save_evaluation_metadata(self, metadata: Dict) -> int:
359355 def save_export_metadata (self , metadata : Dict ) -> int :
360356 """Save export metadata to database with prepared transaction"""
361357 try :
362-
363358 # Use a single connection with enhanced settings
364359 with self .get_connection () as conn :
365360 conn .execute ("BEGIN IMMEDIATE" )
@@ -373,11 +368,12 @@ def save_export_metadata(self, metadata: Dict) -> int:
373368 display_name,
374369 local_export_path,
375370 hf_export_path,
371+ s3_export_path,
376372 job_id,
377373 job_name,
378374 job_status,
379375 job_creator_name
380- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
376+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
381377 """
382378
383379 values = (
@@ -386,6 +382,7 @@ def save_export_metadata(self, metadata: Dict) -> int:
386382 metadata .get ('display_name' ),
387383 metadata .get ('local_export_path' , None ),
388384 metadata .get ('hf_export_path' , None ),
385+ metadata .get ('s3_export_path' , None ), # Add this line
389386 metadata .get ('job_id' , None ),
390387 metadata .get ('job_name' , None ),
391388 metadata .get ('job_status' , None ),
@@ -1131,4 +1128,21 @@ def backup_and_restore_db(self, force_restore: bool = False) -> bool:
11311128 print (f"Force restore failed: { str (restore_error )} " )
11321129 return False
11331130
1131+ def update_s3_path (self , file_name : str , s3_path : str ):
1132+ """Update s3_export_path for a generation"""
1133+ try :
1134+ with self .get_connection () as conn :
1135+ conn .execute ("BEGIN IMMEDIATE" )
1136+ cursor = conn .cursor ()
1137+
1138+ # Update the s3_path
1139+ cursor .execute (
1140+ "UPDATE generation_metadata SET s3_export_path = ? WHERE generate_file_name = ?" ,
1141+ (s3_path , file_name )
1142+ )
1143+ conn .commit ()
1144+ print (f"S3 path update successful for file: { file_name } " )
1145+ except Exception as e :
1146+ print (f"Error updating S3 export path: { str (e )} " )
1147+ raise
11341148
0 commit comments