Skip to content

Commit b1ac472

Browse files
toothstonembuechse
authored andcommitted
Fix db bootstrap logic
An empty db has a current version of 'None', so we have to make sure to check for that first and leave the loop before encountering the '>=' comparison to avoid a TypeError. Signed-off-by: Friedrich Zahn <friedrich.zahn@alasca.cloud>
1 parent 0887aa3 commit b1ac472

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

compliance-monitor/sql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ def db_upgrade_schema(conn: connection, cur: cursor):
194194
# that way just in case we want to use another database at some point
195195
while True:
196196
current = db_get_schema_version(cur)
197-
if current >= SCHEMA_VERSIONS[-1]: # bail if version is too new (but hope it's compatible)
198-
break
199197
if current is None:
200198
# this is an empty db, but it also used to be the case with v1
201199
# I (mbuechse) made sure manually that the value v1 is set on running installations
202200
db_ensure_schema_v4(cur)
203201
db_set_schema_version(cur, 'v4')
204202
conn.commit()
203+
break # Nothing more to do, we bootstrapped with the latest schema version
205204
elif current == 'v1':
206205
db_ensure_schema_v2(cur)
207206
db_upgrade_data_v1_v2(cur)
@@ -219,6 +218,8 @@ def db_upgrade_schema(conn: connection, cur: cursor):
219218
db_ensure_schema_v4(cur)
220219
db_set_schema_version(cur, 'v4')
221220
conn.commit()
221+
elif current >= SCHEMA_VERSIONS[-1]: # bail if version is too new (but hope it's compatible)
222+
break
222223

223224

224225
def db_ensure_schema(conn: connection):

0 commit comments

Comments
 (0)