Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,24 +47,29 @@ def verify_database_tables(conn):
|
|
| 47 |
cursor = conn.cursor()
|
| 48 |
# Get list of all tables
|
| 49 |
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
| 50 |
-
tables = cursor.fetchall()
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# If collections table doesn't exist, force recreate it
|
| 54 |
-
if 'collections' not in
|
| 55 |
-
st.warning("Collections table not found. Force recreating collections tables...")
|
| 56 |
if force_recreate_collections_tables(conn):
|
| 57 |
-
st.
|
| 58 |
else:
|
| 59 |
-
st.error("Failed to
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
tables = cursor.fetchall()
|
| 64 |
-
st.write("Tables after recreation:", [table[0] for table in tables])
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
-
st.error(f"Error verifying tables: {e}")
|
|
|
|
| 68 |
|
| 69 |
def initialize_database():
|
| 70 |
"""Initialize database with persistent storage."""
|
|
|
|
| 47 |
cursor = conn.cursor()
|
| 48 |
# Get list of all tables
|
| 49 |
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
| 50 |
+
tables = [table[0] for table in cursor.fetchall()]
|
| 51 |
+
|
| 52 |
+
# Check for required tables
|
| 53 |
+
required_tables = {
|
| 54 |
+
'documents', 'queries', 'annotations',
|
| 55 |
+
'collections', 'document_collections', 'chats', 'chat_messages'
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
missing_tables = required_tables - set(tables)
|
| 59 |
|
| 60 |
# If collections table doesn't exist, force recreate it
|
| 61 |
+
if 'collections' not in tables:
|
|
|
|
| 62 |
if force_recreate_collections_tables(conn):
|
| 63 |
+
st.session_state.show_debug = True
|
| 64 |
else:
|
| 65 |
+
st.error("Failed to create required database tables.")
|
| 66 |
+
return False
|
| 67 |
+
|
| 68 |
+
return True
|
|
|
|
|
|
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
+
st.error(f"Error verifying database tables: {e}")
|
| 72 |
+
return False
|
| 73 |
|
| 74 |
def initialize_database():
|
| 75 |
"""Initialize database with persistent storage."""
|