Skip to content

Commit b243158

Browse files
committed
add schema to testcache
1 parent d8dd14d commit b243158

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,35 @@ class TestFunction:
6767

6868

6969
class TestsCache:
70+
SCHEMA_VERSION = 1 # Increment this when schema changes
71+
7072
def __init__(self, project_root_path: str | Path) -> None:
7173
self.project_root_path = Path(project_root_path).resolve().as_posix()
7274
self.connection = sqlite3.connect(codeflash_cache_db)
7375
self.cur = self.connection.cursor()
76+
77+
self.cur.execute(
78+
"""
79+
CREATE TABLE IF NOT EXISTS schema_version(
80+
version INTEGER PRIMARY KEY
81+
)
82+
"""
83+
)
84+
85+
self.cur.execute("SELECT version FROM schema_version")
86+
result = self.cur.fetchone()
87+
current_version = result[0] if result else None
88+
89+
if current_version != self.SCHEMA_VERSION:
90+
logger.debug(
91+
f"Schema version mismatch (current: {current_version}, expected: {self.SCHEMA_VERSION}). Recreating tables."
92+
)
93+
self.cur.execute("DROP TABLE IF EXISTS discovered_tests")
94+
self.cur.execute("DROP INDEX IF EXISTS idx_discovered_tests_project_file_path_hash")
95+
self.cur.execute("DELETE FROM schema_version")
96+
self.cur.execute("INSERT INTO schema_version (version) VALUES (?)", (self.SCHEMA_VERSION,))
97+
self.connection.commit()
98+
7499
self.cur.execute(
75100
"""
76101
CREATE TABLE IF NOT EXISTS discovered_tests(

0 commit comments

Comments
 (0)