@@ -149,35 +149,40 @@ def get_cvelist_if_stale(self) -> None:
149
149
self .LOGGER .info (
150
150
"Using cached CVE data (<24h old). Use -u now to update immediately."
151
151
)
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 ):
153
156
self .refresh_cache_and_update_db ()
154
157
self .time_of_last_update = datetime .datetime .today ()
155
158
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 :
157
162
"""Check database is using latest schema"""
158
163
self .LOGGER .debug ("Check database is using latest schema" )
159
164
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"
161
166
result = cursor .execute (schema_check )
162
167
schema_latest = False
163
168
164
169
if not cursor :
165
170
self .db_close ()
166
171
167
- severity , _ = self .table_schemas ()
168
-
169
172
# getting schema from command
170
- lines = severity .split ("(" )[1 ].split ("," )
173
+ lines = table_schema .split ("(" )[1 ].split ("," )
171
174
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 ()
174
177
175
178
# getting current schema from cve_severity
176
179
current_schema = [x [0 ] for x in result .description ]
177
180
178
- if severity_schema == current_schema :
181
+ if table_schema == current_schema :
179
182
schema_latest = True
180
183
184
+ # check for cve_
185
+
181
186
return schema_latest
182
187
183
188
def check_cve_entries (self ) -> bool :
@@ -256,11 +261,20 @@ def init_database(self) -> None:
256
261
cursor .execute (version_range_create )
257
262
cursor .execute (index_range )
258
263
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 ):
260
267
# 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" )
262
269
cursor .execute ("DROP TABLE cve_severity" )
263
270
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
+
264
278
if self .connection is not None :
265
279
self .connection .commit ()
266
280
0 commit comments