2022-11-06 19:50:51 +01:00
|
|
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
|
|
|
|
|
|
CREATE TYPE "QuantityUnit" AS ENUM (
|
|
|
|
'g',
|
|
|
|
'dkg',
|
|
|
|
'kg',
|
|
|
|
'piece'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE photos (
|
2022-11-11 16:32:07 +01:00
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2022-11-06 19:50:51 +01:00
|
|
|
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 (
|
2022-11-11 16:32:07 +01:00
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2022-11-07 10:25:57 +01:00
|
|
|
"name" character varying NOT NULL,
|
2022-11-06 19:50:51 +01:00
|
|
|
category character varying,
|
|
|
|
deliver_days_flag integer DEFAULT 127 NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE product_variants (
|
2022-11-11 16:32:07 +01:00
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2022-11-17 16:56:08 +01:00
|
|
|
product_id integer REFERENCES products (id) ON DELETE CASCADE NOT NULL,
|
2022-11-07 10:25:57 +01:00
|
|
|
"name" character varying NOT NULL,
|
2022-11-06 19:50:51 +01:00
|
|
|
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 (
|
2022-11-11 16:32:07 +01:00
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2022-11-17 16:56:08 +01:00
|
|
|
product_variant_id integer REFERENCES product_variants(id) ON DELETE CASCADE NOT NULL,
|
2022-11-06 19:50:51 +01:00
|
|
|
quantity integer DEFAULT 0 NOT NULL,
|
|
|
|
quantity_unit "QuantityUnit" NOT NULL,
|
|
|
|
CONSTRAINT positive_quantity CHECK ((quantity >= 0))
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE product_photos (
|
2022-11-11 16:32:07 +01:00
|
|
|
id serial NOT NULL PRIMARY KEY,
|
2022-11-17 16:56:08 +01:00
|
|
|
product_variant_id integer REFERENCES product_variants(id) ON DELETE CASCADE NOT NULL,
|
2022-11-06 19:50:51 +01:00
|
|
|
photo_id integer REFERENCES photos(id) NOT NULL
|
|
|
|
);
|