customer/migrations/0004_kits.sql

28 lines
853 B
SQL

CREATE TABLE kits (
id uuid PRIMARY KEY,
offer_id text NOT NULL,
title text NOT NULL,
summary text NOT NULL DEFAULT '',
status text NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'available')),
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE kit_files (
id uuid PRIMARY KEY,
kit_id uuid NOT NULL REFERENCES kits (id) ON DELETE CASCADE,
name text NOT NULL,
content_type text NOT NULL,
size integer NOT NULL,
data bytea NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (kit_id, name)
);
-- Журнал скачиваний: без IP и содержимого.
CREATE TABLE kit_downloads (
id uuid PRIMARY KEY,
file_id uuid NOT NULL REFERENCES kit_files (id) ON DELETE CASCADE,
user_id uuid REFERENCES users (id) ON DELETE SET NULL,
created_at timestamptz NOT NULL DEFAULT now()
);