oceansweep commited on
Commit
04171c3
1 Parent(s): c76c323

Upload SQLite_DB.py

Browse files
App_Function_Libraries/DB/SQLite_DB.py CHANGED
@@ -301,7 +301,8 @@ def create_tables(db) -> None:
301
  is_trash BOOLEAN DEFAULT 0,
302
  trash_date DATETIME,
303
  vector_embedding BLOB,
304
- chunking_status TEXT DEFAULT 'pending'
 
305
  )
306
  ''',
307
  '''
@@ -564,11 +565,14 @@ def sqlite_update_fts_for_media(db, media_id: int):
564
  conn.commit()
565
 
566
 
567
- def sqlite_get_unprocessed_media(db):
568
- with db.get_connection() as conn:
569
- cursor = conn.cursor()
570
- cursor.execute("SELECT id, content, type FROM Media WHERE id NOT IN (SELECT DISTINCT media_id FROM MediaChunks)")
571
- return cursor.fetchall()
 
 
 
572
 
573
  def get_next_media_id():
574
  try:
@@ -580,8 +584,18 @@ def get_next_media_id():
580
  finally:
581
  conn.close()
582
 
 
 
 
 
 
 
 
 
 
 
583
  #
584
- # End of Media-related Functions
585
  #######################################################################################################################
586
 
587
 
@@ -2896,6 +2910,23 @@ def update_media_table(db):
2896
  # Add chunking_status column if it doesn't exist
2897
  add_missing_column_if_not_exists(db, 'Media', 'chunking_status', "TEXT DEFAULT 'pending'")
2898
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2899
  #
2900
  # End of Functions to manage media chunks
2901
  #######################################################################################################################
 
301
  is_trash BOOLEAN DEFAULT 0,
302
  trash_date DATETIME,
303
  vector_embedding BLOB,
304
+ chunking_status TEXT DEFAULT 'pending',
305
+ vector_processing INTEGER DEFAULT 0
306
  )
307
  ''',
308
  '''
 
565
  conn.commit()
566
 
567
 
568
+ def get_unprocessed_media(db):
569
+ query = """
570
+ SELECT id, content, type, COALESCE(title, '') as file_name
571
+ FROM Media
572
+ WHERE vector_processing = 0
573
+ ORDER BY id
574
+ """
575
+ return db.execute_query(query)
576
 
577
  def get_next_media_id():
578
  try:
 
584
  finally:
585
  conn.close()
586
 
587
+
588
+ def mark_media_as_processed(database, media_id):
589
+ try:
590
+ query = "UPDATE Media SET vector_processing = 1 WHERE id = ?"
591
+ database.execute_query(query, (media_id,))
592
+ logger.info(f"Marked media_id {media_id} as processed")
593
+ except Exception as e:
594
+ logger.error(f"Error marking media_id {media_id} as processed: {str(e)}")
595
+ raise
596
+
597
  #
598
+ # End of Vector-chunk-related Functions
599
  #######################################################################################################################
600
 
601
 
 
2910
  # Add chunking_status column if it doesn't exist
2911
  add_missing_column_if_not_exists(db, 'Media', 'chunking_status', "TEXT DEFAULT 'pending'")
2912
 
2913
+ # Vector check FIXME/Delete later
2914
+ def alter_media_table(db):
2915
+ alter_query = '''
2916
+ ALTER TABLE Media ADD COLUMN vector_processing INTEGER DEFAULT 0
2917
+ '''
2918
+ try:
2919
+ db.execute_query(alter_query)
2920
+ logging.info("Media table altered successfully to include vector_processing column.")
2921
+ except Exception as e:
2922
+ logging.error(f"Error altering Media table: {str(e)}")
2923
+ # If the column already exists, SQLite will throw an error, which we can safely ignore
2924
+ if "duplicate column name" not in str(e).lower():
2925
+ raise
2926
+
2927
+ # Vector check FIXME/Delete later
2928
+ alter_media_table(db)
2929
+
2930
  #
2931
  # End of Functions to manage media chunks
2932
  #######################################################################################################################