Fixed code style in db schema definitions.
This commit is contained in:
parent
ce0a01cb7c
commit
9afd86d5ab
1 changed files with 98 additions and 100 deletions
|
@ -1,12 +1,10 @@
|
||||||
|
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
|
|
||||||
SCHEMAS: Dict[int, List[str]] = dict()
|
SCHEMAS: Dict[int, List[str]] = dict()
|
||||||
|
|
||||||
|
SCHEMAS[1] = [
|
||||||
SCHEMAS[1] = ['''
|
'''
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY,
|
||||||
username TEXT UNIQUE NOT NULL,
|
username TEXT UNIQUE NOT NULL,
|
||||||
email TEXT DEFAULT NULL,
|
email TEXT DEFAULT NULL,
|
||||||
|
@ -16,19 +14,19 @@ CREATE TABLE users (
|
||||||
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
||||||
balance INTEGER(8) NOT NULL DEFAULT 0,
|
balance INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
lastchange INTEGER(8) NOT NULL DEFAULT 0
|
lastchange INTEGER(8) NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE products (
|
CREATE TABLE products (
|
||||||
product_id INTEGER PRIMARY KEY,
|
product_id INTEGER PRIMARY KEY,
|
||||||
name TEXT UNIQUE NOT NULL,
|
name TEXT UNIQUE NOT NULL,
|
||||||
stock INTEGER(8) NOT NULL DEFAULT 0,
|
stock INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
price_member INTEGER(8) NOT NULL,
|
price_member INTEGER(8) NOT NULL,
|
||||||
price_non_member INTEGER(8) NOT NULL
|
price_non_member INTEGER(8) NOT NULL
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE consumption (
|
CREATE TABLE consumption (
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
product_id INTEGER NOT NULL,
|
product_id INTEGER NOT NULL,
|
||||||
count INTEGER(8) NOT NULL DEFAULT 0,
|
count INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
|
@ -37,12 +35,12 @@ CREATE TABLE consumption (
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE,
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
FOREIGN KEY (product_id) REFERENCES products(product_id)
|
FOREIGN KEY (product_id) REFERENCES products(product_id)
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''']
|
''']
|
||||||
|
|
||||||
|
SCHEMAS[2] = [
|
||||||
SCHEMAS[2] = ['''
|
'''
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY,
|
||||||
username TEXT UNIQUE NOT NULL,
|
username TEXT UNIQUE NOT NULL,
|
||||||
email TEXT DEFAULT NULL,
|
email TEXT DEFAULT NULL,
|
||||||
|
@ -52,19 +50,19 @@ CREATE TABLE users (
|
||||||
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
is_member INTEGER(1) NOT NULL DEFAULT 1,
|
||||||
balance INTEGER(8) NOT NULL DEFAULT 0,
|
balance INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
lastchange INTEGER(8) NOT NULL DEFAULT 0
|
lastchange INTEGER(8) NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE products (
|
CREATE TABLE products (
|
||||||
product_id INTEGER PRIMARY KEY,
|
product_id INTEGER PRIMARY KEY,
|
||||||
name TEXT UNIQUE NOT NULL,
|
name TEXT UNIQUE NOT NULL,
|
||||||
stock INTEGER(8) NOT NULL DEFAULT 0,
|
stock INTEGER(8) NOT NULL DEFAULT 0,
|
||||||
price_member INTEGER(8) NOT NULL,
|
price_member INTEGER(8) NOT NULL,
|
||||||
price_non_member INTEGER(8) NOT NULL
|
price_non_member INTEGER(8) NOT NULL
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE transactions ( -- "superclass" of the following 3 tables
|
CREATE TABLE transactions ( -- "superclass" of the following 3 tables
|
||||||
ta_id INTEGER PRIMARY KEY,
|
ta_id INTEGER PRIMARY KEY,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
value INTEGER(8) NOT NULL,
|
value INTEGER(8) NOT NULL,
|
||||||
|
@ -72,27 +70,27 @@ CREATE TABLE transactions ( -- "superclass" of the following 3 tables
|
||||||
date INTEGER(8) DEFAULT (STRFTIME('%s', 'now')),
|
date INTEGER(8) DEFAULT (STRFTIME('%s', 'now')),
|
||||||
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE consumptions ( -- transactions involving buying a product
|
CREATE TABLE consumptions ( -- transactions involving buying a product
|
||||||
ta_id INTEGER PRIMARY KEY,
|
ta_id INTEGER PRIMARY KEY,
|
||||||
product_id INTEGER DEFAULT NULL,
|
product_id INTEGER DEFAULT NULL,
|
||||||
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE,
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
FOREIGN KEY (product_id) REFERENCES products(product_id)
|
FOREIGN KEY (product_id) REFERENCES products(product_id)
|
||||||
ON DELETE SET NULL ON UPDATE CASCADE
|
ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE deposits ( -- transactions involving depositing cash
|
CREATE TABLE deposits ( -- transactions involving depositing cash
|
||||||
ta_id INTEGER PRIMARY KEY,
|
ta_id INTEGER PRIMARY KEY,
|
||||||
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
FOREIGN KEY (ta_id) REFERENCES transactions(ta_id)
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''',
|
''',
|
||||||
'''
|
'''
|
||||||
CREATE TABLE modifications ( -- transactions involving balance modification by an admin
|
CREATE TABLE modifications ( -- transactions involving balance modification by an admin
|
||||||
ta_id INTEGER NOT NULL,
|
ta_id INTEGER NOT NULL,
|
||||||
agent_id INTEGER NOT NULL,
|
agent_id INTEGER NOT NULL,
|
||||||
reason TEXT DEFAULT NULL,
|
reason TEXT DEFAULT NULL,
|
||||||
|
@ -101,5 +99,5 @@ CREATE TABLE modifications ( -- transactions involving balance modification by
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE,
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
FOREIGN KEY (agent_id) REFERENCES users(user_id)
|
FOREIGN KEY (agent_id) REFERENCES users(user_id)
|
||||||
ON DELETE CASCADE ON UPDATE CASCADE
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
''']
|
''']
|
||||||
|
|
Loading…
Reference in a new issue