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:
parent
3493f2152f
commit
de59dcc9c4
1 changed files with 2 additions and 5 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue