From de59dcc9c4531c2a45fb1b4a39b1aa60959dedf6 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 8 Jul 2025 15:44:02 +1200 Subject: [PATCH] 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`. --- sbysrc/sby_status.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sbysrc/sby_status.py b/sbysrc/sby_status.py index 3e5293f..41990b6 100644 --- a/sbysrc/sby_status.py +++ b/sbysrc/sby_status.py @@ -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,8 +121,7 @@ class SbyStatusDb: else: break - if setup: - self._setup() + self._setup() if task is not None: self.task_id = self.create_task(workdir=task.workdir, mode=task.opt_mode) @@ -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)