From acc0a87fcdd1ef09f224ba09a966c9461b191894 Mon Sep 17 00:00:00 2001 From: Rens Oliemans Date: Wed, 19 Jan 2022 23:27:39 +0100 Subject: [PATCH 1/3] Update links.sqlite.empty to use new datastructure Added the column 'note' --- data/links.sqlite.empty | Bin 12288 -> 12288 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/links.sqlite.empty b/data/links.sqlite.empty index 0a3b0779eb459dfe856110a91396c95a65aff6eb..8ac3def1cc9eb933568dd55b39d5f572b78e3389 100644 GIT binary patch delta 80 zcmZojXh@hKEhx*tz`)Fa0PGWWj0I&G^nw$3`F}7l@ry9jyU0hU@ bu_<`65&vv19WDh01%vz`)Fa0IU;rj0L3`^nw$3`F}7l@oO;fYw(}nEGV#pkE>CIkzHI= Rl(9*BvK;^H&1d Date: Wed, 19 Jan 2022 23:35:36 +0100 Subject: [PATCH 2/3] Create table on app start Remove links.sql since we moved that information in the python code. --- data/links.sql | 7 ------- links/db.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) delete mode 100644 data/links.sql diff --git a/data/links.sql b/data/links.sql deleted file mode 100644 index 1a4672e..0000000 --- a/data/links.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE link ( - entrance TEXT NOT NULL UNIQUE, - destination TEXT NULL, - one_way INTEGER NOT NULL DEFAULT 0, - block TEXT NULL, - note TEXT NULL -); \ No newline at end of file diff --git a/links/db.py b/links/db.py index 267e071..380b61f 100644 --- a/links/db.py +++ b/links/db.py @@ -3,11 +3,24 @@ import sqlite3 from links.link import Link from util.blocked import Blocked +CREATE = """ +CREATE TABLE IF NOT EXISTS link ( + entrance TEXT NOT NULL UNIQUE, + destination TEXT NULL, + one_way INTEGER NOT NULL DEFAULT 0, + block TEXT NULL, + note TEXT NULL +); +""" + class Db: def __init__(self, database): self._database = database + def create_table(self): + self._cursor.execute(CREATE) + def insert(self, link: Link): block = link.block.value if link.block is not None else None self._cursor.execute("INSERT INTO link VALUES (?, ?, ?, ?, ?)", @@ -53,6 +66,7 @@ class Db: def __enter__(self): self._conn = sqlite3.connect(self._database, isolation_level=None) self._cursor = self._conn.cursor() + self.create_table() return self def __exit__(self, exc_type, exc_val, exc_tb): -- GitLab From 44c1cfd9e5150ae1de889bec5a8da278eaa9e373 Mon Sep 17 00:00:00 2001 From: Rens Oliemans Date: Wed, 19 Jan 2022 23:36:56 +0100 Subject: [PATCH 3/3] Move database and log file to root directory This is done since having it in a data/ directory had some problems with the build if the directory didn't exist. We might add them in a directory later, but this is the easiest to get a build working. --- .gitignore | 1 + main.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d46c2b0..7130303 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ tags* .env data/*.sqlite +*.sqlite # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python diff --git a/main.py b/main.py index 61dc520..3aed464 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,5 @@ import sys import logging -from os.path import join from PySide6.QtCore import QCoreApplication, Qt from PySide6.QtWidgets import QApplication @@ -10,9 +9,9 @@ from pokerandom import PokeRandom from links.db import Db from timer import connect_shift -logging.basicConfig(filename=join('data', 'pokerandom.log'), level=logging.DEBUG, +logging.basicConfig(filename='pokerandom.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s') -database = join('data', 'links.sqlite') +database = 'pokerandom_db.sqlite' if __name__ == '__main__': -- GitLab