@@ -218,11 +218,11 @@ def deletePromptEntry(self, group_id, id=None):
218
218
219
219
def __createThread (self ):
220
220
try :
221
- # Create new thread table if not exists
222
- table_name_new_exists = self .__c .execute (
221
+ # Create thread table if not exists
222
+ thread_tb_exists = self .__c .execute (
223
223
f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{ THREAD_TABLE_NAME } '" ).fetchone ()[
224
224
0 ] == 1
225
- if table_name_new_exists :
225
+ if thread_tb_exists :
226
226
pass
227
227
else :
228
228
# If user uses app for the first time, create a table
@@ -232,13 +232,15 @@ def __createThread(self):
232
232
name TEXT,
233
233
update_dt DATETIME,
234
234
insert_dt DATETIME DEFAULT CURRENT_TIMESTAMP)''' )
235
- # Create message table
236
- self .__createMessage ()
237
- # Create new thread trigger if not exists
238
- trigger_name_new_exists = self .__c .execute (
235
+
236
+ # Create message table
237
+ self .__createMessage ()
238
+
239
+ # Create trigger if not exists
240
+ thread_trigger_exists = self .__c .execute (
239
241
f"SELECT count(*) FROM sqlite_master WHERE type='trigger' AND name='{ THREAD_TRIGGER_NAME } '" ).fetchone ()[
240
242
0 ] == 1
241
- if trigger_name_new_exists :
243
+ if thread_trigger_exists :
242
244
pass
243
245
else :
244
246
# Create a trigger to update the update_dt column with the current timestamp
@@ -370,10 +372,16 @@ def __createMessage(self):
370
372
f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{ MESSAGE_TABLE_NAME } '" )
371
373
if self .__c .fetchone ()[0 ] == 1 :
372
374
# TODO WILL_BE_REMOVED_AFTER v1.6.0
373
- # Add is_g4f, g4f_platform to the table
374
- self .__c .execute (f'ALTER TABLE { MESSAGE_TABLE_NAME } ADD '
375
- f'COLUMN is_g4f INT DEFAULT 0'
376
- f', g4f_platform VARCHAR(255)' )
375
+ # If there is no is_g4f column, add it
376
+ self .__c .execute (f"PRAGMA table_info({ MESSAGE_TABLE_NAME } )" )
377
+ columns = self .__c .fetchall ()
378
+ if 'is_g4f' not in [col [1 ] for col in columns ]:
379
+ # Add is_g4f, g4f_platform to the table
380
+ self .__c .execute (f'ALTER TABLE { MESSAGE_TABLE_NAME } ADD COLUMN is_g4f INT DEFAULT 0' )
381
+
382
+ # If there is no g4f_platform column, add it
383
+ if 'g4f_platform' not in [col [1 ] for col in columns ]:
384
+ self .__c .execute (f"ALTER TABLE { MESSAGE_TABLE_NAME } ADD COLUMN g4f_platform VARCHAR(255) DEFAULT ''" )
377
385
else :
378
386
# Create message table and triggers
379
387
self .__c .execute (f'''CREATE TABLE { MESSAGE_TABLE_NAME }
0 commit comments