3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-08-15 01:15:30 +00:00

statusdb: Safer setup

Always call `_setup()`, but use `CREATE TABLE IF NOT EXISTS`. The sql schema doesn't include this, so inject it during the setup instead of adding it to the `SQLSCRIPT`.
This commit is contained in:
Krystine Sherwin 2025-07-08 15:44:02 +12:00
parent 3493f2152f
commit de59dcc9c4
No known key found for this signature in database

View file

@ -98,8 +98,6 @@ class SbyStatusDb:
self.debug = False
self.task = task
setup = not os.path.exists(path)
self.con = sqlite3.connect(path, isolation_level=None, timeout=timeout)
self.db = self.con.cursor()
self.db.row_factory = sqlite3.Row
@ -123,7 +121,6 @@ class SbyStatusDb:
else:
break
if setup:
self._setup()
if task is not None:
@ -139,7 +136,7 @@ class SbyStatusDb:
@transaction
def _setup(self):
for statement in SQLSCRIPT.split(";\n"):
statement = statement.strip()
statement = statement.strip().replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS")
if statement:
self.db.execute(statement)