test: Add test for pgvector to confirm database deletion is working

Added assert to verify all tables in database have been cleared.
Added method to SqlAlchemyAdapter to get all table names in database.

Test COG-488
This commit is contained in:
Igor Ilic 2024-11-20 17:11:23 +01:00
parent a8aefd57ef
commit b60f2603f4
2 changed files with 28 additions and 1 deletions

View file

@ -130,6 +130,29 @@ class SQLAlchemyAdapter():
return metadata.tables[full_table_name]
raise ValueError(f"Table '{full_table_name}' not found.")
async def get_table_names(self) -> List[str]:
"""
Return a list of all tables names in database
"""
table_names = []
async with self.engine.begin() as connection:
if self.engine.dialect.name == "sqlite":
await connection.run_sync(Base.metadata.reflect)
for table in Base.metadata.tables:
table_names.append(str(table))
else:
schema_list = await self.get_schema_list()
# Create a MetaData instance to load table information
metadata = MetaData()
# Drop all tables from all schemas
for schema_name in schema_list:
# Load the schema information into the MetaData object
await connection.run_sync(metadata.reflect, schema=schema_name)
for table in metadata.sorted_tables:
table_names.append(str(table))
metadata.clear()
return table_names
async def get_data(self, table_name: str, filters: dict = None):
async with self.engine.begin() as connection:

View file

@ -87,9 +87,13 @@ async def main():
print(f"{result}\n")
history = await cognee.get_search_history()
assert len(history) == 6, "Search history is not correct."
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
tables_in_database = await vector_engine.get_table_names()
assert len(tables_in_database) == 0, "The database is not empty"
if __name__ == "__main__":
import asyncio