47 lines
1.3 KiB
SQL
47 lines
1.3 KiB
SQL
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
|
|
CREATE TYPE "QuantityUnit" AS ENUM (
|
|
'g',
|
|
'dkg',
|
|
'kg',
|
|
'piece'
|
|
);
|
|
|
|
CREATE TABLE photos (
|
|
id integer NOT NULL PRIMARY KEY,
|
|
local_path character varying NOT NULL,
|
|
file_name character varying NOT NULL,
|
|
unique_name text DEFAULT (gen_random_uuid())::text NOT NULL
|
|
);
|
|
|
|
CREATE TABLE products (
|
|
id integer NOT NULL PRIMARY KEY,
|
|
"name" character varying NOT NULL,
|
|
category character varying,
|
|
deliver_days_flag integer DEFAULT 127 NOT NULL
|
|
);
|
|
|
|
CREATE TABLE product_variants (
|
|
id integer NOT NULL PRIMARY KEY,
|
|
product_id integer REFERENCES products (id) NOT NULL,
|
|
"name" character varying NOT NULL,
|
|
short_description character varying NOT NULL,
|
|
long_description character varying NOT NULL,
|
|
price integer NOT NULL,
|
|
CONSTRAINT non_negative CHECK ((price >= 0))
|
|
);
|
|
|
|
CREATE TABLE stocks (
|
|
id integer NOT NULL PRIMARY KEY,
|
|
product_variant_id integer REFERENCES product_variants(id) NOT NULL,
|
|
quantity integer DEFAULT 0 NOT NULL,
|
|
quantity_unit "QuantityUnit" NOT NULL,
|
|
CONSTRAINT positive_quantity CHECK ((quantity >= 0))
|
|
);
|
|
|
|
CREATE TABLE product_photos (
|
|
id integer NOT NULL PRIMARY KEY,
|
|
product_variant_id integer REFERENCES product_variants(id) NOT NULL,
|
|
photo_id integer REFERENCES photos(id) NOT NULL
|
|
);
|