forked from s3lph/matemat
Merge branch 'main' of ssh://git.kabelsalat.ch:2222/weva/matemat
This commit is contained in:
commit
6e9f60eb36
5 changed files with 134 additions and 8 deletions
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
__version__ = '0.4.1'
|
__version__ = '0.4.2'
|
||||||
|
|
|
@ -309,3 +309,31 @@ def migrate_schema_8_to_9(c: sqlite3.Cursor):
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
)
|
)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_schema_9_to_10(c: sqlite3.Cursor):
|
||||||
|
c.execute('''
|
||||||
|
ALTER TABLE users RENAME TO users_old
|
||||||
|
''')
|
||||||
|
c.execute('''
|
||||||
|
CREATE TABLE users (
|
||||||
|
user_id INTEGER PRIMARY KEY,
|
||||||
|
username TEXT UNIQUE NOT NULL COLLATE NOCASE,
|
||||||
|
email TEXT DEFAULT NULL,
|
||||||
|
password TEXT NOT NULL,
|
||||||
|
touchkey TEXT DEFAULT NULL,
|
||||||
|
is_admin INTEGER(1) NOT NULL DEFAULT 0,
|
||||||
|
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
||||||
|
balance INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
lastchange INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
receipt_pref INTEGER(1) NOT NULL DEFAULT 0,
|
||||||
|
created INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
logout_after_purchase INTEGER(1) DEFAULT 0
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
c.execute('''
|
||||||
|
INSERT INTO users SELECT * FROM users_old
|
||||||
|
''')
|
||||||
|
c.execute('''
|
||||||
|
DROP TABLE users_old
|
||||||
|
''')
|
||||||
|
|
|
@ -669,3 +669,96 @@ SCHEMAS[9] = [
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''']
|
''']
|
||||||
|
|
||||||
|
|
||||||
|
SCHEMAS[10] = [
|
||||||
|
'''
|
||||||
|
CREATE TABLE users (
|
||||||
|
user_id INTEGER PRIMARY KEY,
|
||||||
|
username TEXT UNIQUE NOT NULL COLLATE NOCASE,
|
||||||
|
email TEXT DEFAULT NULL,
|
||||||
|
password TEXT NOT NULL,
|
||||||
|
touchkey TEXT DEFAULT NULL,
|
||||||
|
is_admin INTEGER(1) NOT NULL DEFAULT 0,
|
||||||
|
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
||||||
|
balance INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
lastchange INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
receipt_pref INTEGER(1) NOT NULL DEFAULT 0,
|
||||||
|
created INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
logout_after_purchase INTEGER(1) DEFAULT 0
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE products (
|
||||||
|
product_id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT UNIQUE NOT NULL,
|
||||||
|
stock INTEGER(8) DEFAULT 0,
|
||||||
|
stockable INTEGER(1) DEFAULT 1,
|
||||||
|
price_member INTEGER(8) NOT NULL,
|
||||||
|
price_non_member INTEGER(8) NOT NULL,
|
||||||
|
custom_price INTEGER(1) DEFAULT 0,
|
||||||
|
ean TEXT UNIQUE DEFAULT NULL
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE transactions ( -- "superclass" of the following 3 tables
|
||||||
|
ta_id INTEGER PRIMARY KEY,
|
||||||
|
user_id INTEGER DEFAULT NULL,
|
||||||
|
value INTEGER(8) NOT NULL,
|
||||||
|
old_balance INTEGER(8) NOT NULL,
|
||||||
|
date INTEGER(8) DEFAULT (STRFTIME('%s', 'now')),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||||
|
ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE consumptions ( -- transactions involving buying a product
|
||||||
|
ta_id INTEGER PRIMARY KEY,
|
||||||
|
product TEXT NOT NULL,
|
||||||
|
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE deposits ( -- transactions involving depositing cash
|
||||||
|
ta_id INTEGER PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE modifications ( -- transactions involving balance modification by an admin
|
||||||
|
ta_id INTEGER NOT NULL,
|
||||||
|
agent TEXT NOT NULL,
|
||||||
|
reason TEXT DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ta_id),
|
||||||
|
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE receipts ( -- receipts sent to the users
|
||||||
|
receipt_id INTEGER PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
first_ta_id INTEGER DEFAULT NULL,
|
||||||
|
last_ta_id INTEGER DEFAULT NULL,
|
||||||
|
date INTEGER(8) DEFAULT (STRFTIME('%s', 'now')),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY (first_ta_id) REFERENCES transactions(ta_id)
|
||||||
|
ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY (last_ta_id) REFERENCES transactions(ta_id)
|
||||||
|
ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''',
|
||||||
|
'''
|
||||||
|
CREATE TABLE tokens ( -- authentication tokens such as barcodes
|
||||||
|
token_id INTEGER PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
token TEXT UNIQUE NOT NULL,
|
||||||
|
name TEXT UNIQUE NOT NULL,
|
||||||
|
date INTEGER(8) DEFAULT (STRFTIME('%s', 'now')),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
''']
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DatabaseTransaction(object):
|
||||||
|
|
||||||
class DatabaseWrapper(object):
|
class DatabaseWrapper(object):
|
||||||
|
|
||||||
SCHEMA_VERSION = 9
|
SCHEMA_VERSION = 10
|
||||||
|
|
||||||
def __init__(self, filename: str) -> None:
|
def __init__(self, filename: str) -> None:
|
||||||
self._filename: str = filename
|
self._filename: str = filename
|
||||||
|
@ -78,8 +78,7 @@ class DatabaseWrapper(object):
|
||||||
|
|
||||||
def _upgrade(self, from_version: int, to_version: int) -> None:
|
def _upgrade(self, from_version: int, to_version: int) -> None:
|
||||||
with self.transaction() as c:
|
with self.transaction() as c:
|
||||||
# Note to future s3lph: If there are further migrations, also consider upgrades like 1 -> 3
|
if from_version <= 1 and to_version >= 2:
|
||||||
if from_version == 1 and to_version >= 2:
|
|
||||||
migrate_schema_1_to_2(c)
|
migrate_schema_1_to_2(c)
|
||||||
if from_version <= 2 and to_version >= 3:
|
if from_version <= 2 and to_version >= 3:
|
||||||
migrate_schema_2_to_3(c)
|
migrate_schema_2_to_3(c)
|
||||||
|
@ -97,6 +96,8 @@ class DatabaseWrapper(object):
|
||||||
migrate_schema_7_to_8(c)
|
migrate_schema_7_to_8(c)
|
||||||
if from_version <= 8 and to_version >= 9:
|
if from_version <= 8 and to_version >= 9:
|
||||||
migrate_schema_8_to_9(c)
|
migrate_schema_8_to_9(c)
|
||||||
|
if from_version <= 9 and to_version >= 10:
|
||||||
|
migrate_schema_9_to_10(c)
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
if self.is_connected():
|
if self.is_connected():
|
||||||
|
|
|
@ -50,8 +50,10 @@
|
||||||
<td>{{ '✓' if user.is_admin else '✗' }}</td>
|
<td>{{ '✓' if user.is_admin else '✗' }}</td>
|
||||||
<td>{{ '✓' if user.logout_after_purchase else '✗' }}</td>
|
<td>{{ '✓' if user.logout_after_purchase else '✗' }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
<a class="btn btn-primary" href="/moduser?userid={{ user.id }}">Edit</a>
|
<a class="btn btn-primary" href="/moduser?userid={{ user.id }}">Edit</a>
|
||||||
<a class="btn btn-danger" href="/moduser?userid={{ user.id }}&change=del">Delete</a>
|
<a class="btn btn-danger" href="/moduser?userid={{ user.id }}&change=del">Delete</a>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -104,8 +106,10 @@
|
||||||
<td>{{ '✓' if product.stockable else '✗' }}</td>
|
<td>{{ '✓' if product.stockable else '✗' }}</td>
|
||||||
<td><img style="height: 2em;" src="/static/upload/thumbnails/products/{{ product.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ product.name }}" draggable="false"></td>
|
<td><img style="height: 2em;" src="/static/upload/thumbnails/products/{{ product.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ product.name }}" draggable="false"></td>
|
||||||
<td>
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
<a class="btn btn-primary" href="/modproduct?productid={{ product.id }}">Edit</a>
|
<a class="btn btn-primary" href="/modproduct?productid={{ product.id }}">Edit</a>
|
||||||
<a class="btn btn-danger" href="/modproduct?productid={{ product.id }}&change=del">Delete</a>
|
<a class="btn btn-danger" href="/modproduct?productid={{ product.id }}&change=del">Delete</a>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue