Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from datetime import datetime
|
|
| 8 |
from threading import Lock
|
| 9 |
|
| 10 |
from utils.database import (
|
| 11 |
-
|
| 12 |
create_connection,
|
| 13 |
create_tables,
|
| 14 |
get_all_documents,
|
|
@@ -20,6 +20,7 @@ from utils.database import (
|
|
| 20 |
remove_from_collection,
|
| 21 |
update_collection,
|
| 22 |
get_collection_documents,
|
|
|
|
| 23 |
|
| 24 |
# Search functionality
|
| 25 |
search_documents
|
|
@@ -30,6 +31,28 @@ from components.chat import display_chat_interface
|
|
| 30 |
# Create locks for thread-safe operations
|
| 31 |
conn_lock = Lock()
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def initialize_database():
|
| 34 |
"""Initialize database with persistent storage."""
|
| 35 |
try:
|
|
@@ -59,10 +82,15 @@ def initialize_database():
|
|
| 59 |
# Create all tables (includes collection tables)
|
| 60 |
create_tables(conn)
|
| 61 |
st.session_state.db_conn = conn
|
|
|
|
|
|
|
|
|
|
| 62 |
return True
|
| 63 |
else:
|
| 64 |
return False
|
| 65 |
else:
|
|
|
|
|
|
|
| 66 |
return True
|
| 67 |
|
| 68 |
except Exception as e:
|
|
|
|
| 8 |
from threading import Lock
|
| 9 |
|
| 10 |
from utils.database import (
|
| 11 |
+
# Base database operations
|
| 12 |
create_connection,
|
| 13 |
create_tables,
|
| 14 |
get_all_documents,
|
|
|
|
| 20 |
remove_from_collection,
|
| 21 |
update_collection,
|
| 22 |
get_collection_documents,
|
| 23 |
+
handle_document_upload,
|
| 24 |
|
| 25 |
# Search functionality
|
| 26 |
search_documents
|
|
|
|
| 31 |
# Create locks for thread-safe operations
|
| 32 |
conn_lock = Lock()
|
| 33 |
|
| 34 |
+
def verify_database_tables(conn):
|
| 35 |
+
"""Verify that all required tables exist."""
|
| 36 |
+
try:
|
| 37 |
+
cursor = conn.cursor()
|
| 38 |
+
# Get list of all tables
|
| 39 |
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
| 40 |
+
tables = cursor.fetchall()
|
| 41 |
+
st.write("Existing tables:", [table[0] for table in tables])
|
| 42 |
+
|
| 43 |
+
# If collections table doesn't exist, recreate tables
|
| 44 |
+
if 'collections' not in [table[0] for table in tables]:
|
| 45 |
+
st.warning("Collections table not found. Recreating tables...")
|
| 46 |
+
create_tables(conn)
|
| 47 |
+
|
| 48 |
+
# Verify again
|
| 49 |
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
| 50 |
+
tables = cursor.fetchall()
|
| 51 |
+
st.write("Tables after recreation:", [table[0] for table in tables])
|
| 52 |
+
|
| 53 |
+
except Exception as e:
|
| 54 |
+
st.error(f"Error verifying tables: {e}")
|
| 55 |
+
|
| 56 |
def initialize_database():
|
| 57 |
"""Initialize database with persistent storage."""
|
| 58 |
try:
|
|
|
|
| 82 |
# Create all tables (includes collection tables)
|
| 83 |
create_tables(conn)
|
| 84 |
st.session_state.db_conn = conn
|
| 85 |
+
|
| 86 |
+
# Verify tables were created
|
| 87 |
+
verify_database_tables(conn)
|
| 88 |
return True
|
| 89 |
else:
|
| 90 |
return False
|
| 91 |
else:
|
| 92 |
+
# Verify tables exist in existing connection
|
| 93 |
+
verify_database_tables(st.session_state.db_conn)
|
| 94 |
return True
|
| 95 |
|
| 96 |
except Exception as e:
|