39 lines
1.2 KiB
Plaintext
39 lines
1.2 KiB
Plaintext
|
CREATE TABLE IF NOT EXISTS Users(
|
||
|
ID SERIAL PRIMARY KEY,
|
||
|
username VARCHAR(32) UNIQUE,
|
||
|
password CHAR(60), -- hashed with salt using bcrypt
|
||
|
groups INT[] -- IDs of groups user is a member of
|
||
|
);
|
||
|
|
||
|
CREATE TABLE IF NOT EXISTS Groups (
|
||
|
ID SERIAL PRIMARY KEY,
|
||
|
name VARCHAR(64) UNIQUE,
|
||
|
admin_id INT,
|
||
|
password VARCHAR(64) -- password is required to join a group. Set by admin
|
||
|
);
|
||
|
|
||
|
CREATE TABLE IF NOT EXISTS Abstract_products (
|
||
|
ID SERIAL PRIMARY KEY,
|
||
|
group_id INT, -- Abstract products are tied to a group of users they were created by
|
||
|
barcode CHAR(13), -- EAN13
|
||
|
name VARCHAR(128),
|
||
|
net_weight REAL,
|
||
|
image_filename CHAR(32), -- generated by taking md5 hash of an image
|
||
|
category INT, -- link to a category id
|
||
|
unit INT -- link to a unit id, not stored in database due to locale nature, using predefined order instead: kg = 0, g, l, ml, pc.
|
||
|
);
|
||
|
|
||
|
CREATE TABLE IF NOT EXISTS Categories (
|
||
|
ID SERIAL PRIMARY KEY,
|
||
|
group_id INT,
|
||
|
name VARCHAR(64)
|
||
|
);
|
||
|
|
||
|
CREATE TABLE IF NOT EXISTS Products (
|
||
|
ID SERIAL PRIMARY KEY,
|
||
|
group_id INT,
|
||
|
abstract_product_id INT,
|
||
|
amount INT,
|
||
|
date_of_production DATE,
|
||
|
expiry_date DATE
|
||
|
);
|