@@ -149,35 +149,40 @@ def get_cvelist_if_stale(self) -> None:
149149 self .LOGGER .info (
150150 "Using cached CVE data (<24h old). Use -u now to update immediately."
151151 )
152- if not self .latest_schema ():
152+ severity_schema , range_schema = self .table_schemas ()
153+ if not self .latest_schema (
154+ "cve_severity" , severity_schema
155+ ) or not self .latest_schema ("cve_range" , range_schema ):
153156 self .refresh_cache_and_update_db ()
154157 self .time_of_last_update = datetime .datetime .today ()
155158
156- def latest_schema (self , cursor : sqlite3 .Cursor | None = None ) -> bool :
159+ def latest_schema (
160+ self , table_name : str , table_schema : str , cursor : sqlite3 .Cursor | None = None
161+ ) -> bool :
157162 """Check database is using latest schema"""
158163 self .LOGGER .debug ("Check database is using latest schema" )
159164 cursor = self .db_open_and_get_cursor ()
160- schema_check = "SELECT * FROM cve_severity WHERE 1=0"
165+ schema_check = f "SELECT * FROM { table_name } WHERE 1=0"
161166 result = cursor .execute (schema_check )
162167 schema_latest = False
163168
164169 if not cursor :
165170 self .db_close ()
166171
167- severity , _ = self .table_schemas ()
168-
169172 # getting schema from command
170- lines = severity .split ("(" )[1 ].split ("," )
173+ lines = table_schema .split ("(" )[1 ].split ("," )
171174
172- severity_schema = [x .split ("\n " )[1 ].strip ().split (" " )[0 ] for x in lines ]
173- severity_schema .pop ()
175+ table_schema = [x .split ("\n " )[1 ].strip ().split (" " )[0 ] for x in lines ]
176+ table_schema .pop ()
174177
175178 # getting current schema from cve_severity
176179 current_schema = [x [0 ] for x in result .description ]
177180
178- if severity_schema == current_schema :
181+ if table_schema == current_schema :
179182 schema_latest = True
180183
184+ # check for cve_
185+
181186 return schema_latest
182187
183188 def check_cve_entries (self ) -> bool :
@@ -256,11 +261,20 @@ def init_database(self) -> None:
256261 cursor .execute (version_range_create )
257262 cursor .execute (index_range )
258263
259- if not self .latest_schema (cursor ):
264+ severity_schema , range_schema = self .table_schemas ()
265+ # Check schema on cve_severity
266+ if not self .latest_schema ("cve_severity" , severity_schema , cursor ):
260267 # Recreate table using latest schema
261- self .LOGGER .info ("Upgrading database to latest schema" )
268+ self .LOGGER .info ("Upgrading database cve_severity to latest schema" )
262269 cursor .execute ("DROP TABLE cve_severity" )
263270 cursor .execute (cve_data_create )
271+
272+ # Check schema on cve_range
273+ if not self .latest_schema ("cve_range" , range_schema , cursor ):
274+ self .LOGGER .info ("Upgrading database cve_range to latest schema" )
275+ cursor .execute ("DROP TABLE cve_range" )
276+ cursor .execute (version_range_create )
277+
264278 if self .connection is not None :
265279 self .connection .commit ()
266280
0 commit comments