Advertisement
KSlacker

Untitled

Oct 6th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create table if not exists user_roles
  2. (
  3.     id   bigserial primary key,
  4.     name text not null
  5. );
  6. create unique index uq__user_roles__name on user_roles (name);
  7. create unique index uq__user_roles__name on user_roles (name);
  8. comment on table user_roles is 'Роли пользователей';
  9. comment on column user_roles.id is 'Идентификатор роли';
  10. comment on column user_roles.name is 'Название роли';
  11.  
  12. create table if not exists users
  13. (
  14.     id         bigserial primary key,
  15.     email      text                                                    not null,
  16.     password   text                                                    not null,
  17.     role_id    bigint                                                  not null,
  18.     created_at timestamptz default timezone('utc', now())::timestamptz not null,
  19.     updated_at timestamptz default timezone('utc', now())::timestamptz not null,
  20.  
  21.     constraint fk__users__user_roles foreign key (role_id) references user_roles (id)
  22. );
  23. create unique index uq__users__email on users (email);
  24. comment on table users is 'Пользователи';
  25. comment on column users.id is 'Идентификатор пользователя';
  26. comment on column users.email is 'email пользователя';
  27. comment on column users.password is 'Хеш пароля пользователя';
  28. comment on column users.role_id is 'Идентификатор роли пользователя';
  29. comment on column users.created_at is 'Дата и время создания записи';
  30. comment on column users.updated_at is 'Дата и время обновления записи';
  31.  
  32. create table if not exists item_categories
  33. (
  34.     id   bigserial primary key,
  35.     name text not null
  36. );
  37. create unique index uq__item_categories__name on item_categories (name);
  38. comment on table item_categories is 'Категории товаров';
  39. comment on column item_categories.id is 'Идентификатор категории товаров';
  40. comment on column item_categories.name is 'Название категории товаров';
  41.  
  42. create table if not exists item_types
  43. (
  44.     id   bigserial primary key,
  45.     name text not null
  46. );
  47. create unique index uq__item_types__name on item_types (name);
  48. comment on table item_types is 'Типы товаров';
  49. comment on column item_types.id is 'Идентификатор типа товаров';
  50. comment on column item_types.name is 'Название типа товаров';
  51.  
  52. create table if not exists item_groups
  53. (
  54.     id               text primary key,
  55.     title            text   not null,
  56.     item_category_id bigint not null,
  57.     item_type_id     bigint not null,
  58.     description      text,
  59.  
  60.     constraint fk__item_groups__item_categories foreign key (item_category_id) references item_categories (id),
  61.     constraint fk__item_groups__item_types foreign key (item_type_id) references item_types (id)
  62. );
  63. comment on table item_groups is 'Группы товаров';
  64. comment on column item_groups.id is 'Идентификатор группы товаров';
  65. comment on column item_groups.title is 'Наименование группы товаров';
  66. comment on column item_groups.item_category_id is 'Идентификатор категории товара';
  67. comment on column item_groups.item_type_id is 'Идентификатор типа товара';
  68. comment on column item_groups.description is 'Описание группы товаров';
  69.  
  70. create table if not exists item_sizes(
  71.     id bigserial primary key,
  72.     name text not null
  73. );
  74. create unique index uq__item_sizes__name on item_sizes (name);
  75. comment on table item_sizes is 'Размеры товаров';
  76. comment on column item_sizes.id is 'Идентификатор размера';
  77. comment on column item_sizes.name is 'Название размера';
  78.  
  79.  
  80. create table if not exists items
  81. (
  82.     id            bigserial primary key,
  83.     item_group_id text                                                    not null,
  84.     item_size_id  bigint                                                  not null,
  85.     default_price decimal                                                 not null,
  86.     created_at    timestamptz default timezone('utc', now())::timestamptz not null,
  87.     updated_at    timestamptz default timezone('utc', now())::timestamptz not null,
  88.  
  89.     constraint fk__items__item_groups foreign key (item_group_id) references item_groups (id),
  90.     constraint fk__items__item_sizes foreign key (item_size_id) references item_sizes (id)
  91. );
  92. comment on table items is 'Товары';
  93. comment on column items.id is 'Идентификатор товара';
  94. comment on column items.item_group_id is 'Идентификатор группы товаров';
  95. comment on column items.item_size_id is 'Идентификатор размера';
  96. comment on column items.default_price is 'Цена товара по умолчанию';
  97. comment on column items.created_at is 'Дата и время создания записи';
  98. comment on column items.updated_at is 'Дата и время обновления записи';
  99.  
  100. create table if not exists item_balances
  101. (
  102.     item_id      bigint primary key,
  103.     total_qty    integer                                                 not null,
  104.     reserved_qty integer     default 0                                   not null,
  105.     updated_at   timestamptz default timezone('utc', now())::timestamptz not null,
  106.  
  107.     constraint fk__item_balances__items foreign key (item_id) references items (id)
  108. );
  109. comment on table item_balances is 'Балансы товаров';
  110. comment on column item_balances.item_id is 'Идентификатор товара';
  111. comment on column item_balances.total_qty is 'Общее количество товара';
  112. comment on column item_balances.reserved_qty is 'Зарезервированное количество товара';
  113. comment on column item_balances.updated_at is 'Дата и время обновления записи';
  114.  
  115. create table if not exists item_collections
  116. (
  117.     id           bigserial primary key,
  118.     title        text                                                    not null,
  119.     description  text,
  120.     image_url    text,
  121.     active_until timestamptz default timezone('utc', now())::timestamptz
  122. );
  123. comment on table item_collections is 'Коллекции товаров';
  124. comment on column item_collections.id is 'Идентификатор коллекции товаров';
  125. comment on column item_collections.title is 'Название коллекции товаров';
  126. comment on column item_collections.description is 'Описание коллекции товаров';
  127. comment on column item_collections.image_url is 'Ссылка на картинку для коллекции товаров';
  128. comment on column item_collections.active_until is 'Дата и время, до которого коллекция активна';
  129.  
  130. create table if not exists item_collection_item_groups
  131. (
  132.     item_collection_id bigint not null,
  133.     item_group_id      text not null,
  134.  
  135.     primary key (item_collection_id, item_group_id),
  136.     constraint fk__item_collection_item_groups__item_collections foreign key (item_collection_id) references item_collections (id),
  137.     constraint fk__item_collection_item_groups__item_groups foreign key (item_group_id) references item_groups (id)
  138. );
  139. comment on table item_collection_item_groups is 'Товары в коллекциях';
  140. comment on column item_collection_item_groups.item_collection_id is 'Идентификатор коллекции товаров';
  141. comment on column item_collection_item_groups.item_group_id is 'Идентификатор группы товаров';
  142.  
  143. create table if not exists shopping_cart_items
  144. (
  145.     user_id    bigint,
  146.     item_id    bigint,
  147.     item_price decimal not null,
  148.     item_qty   integer not null,
  149.  
  150.     primary key (user_id, item_id),
  151.     constraint fk__shopping_cart_items__users foreign key (user_id) references users (id),
  152.     constraint fk__shopping_cart_items__items foreign key (item_id) references items (id)
  153. );
  154. comment on table shopping_cart_items is 'Товары в корзине пользователя';
  155. comment on column shopping_cart_items.user_id is 'Идентификатор пользователя';
  156. comment on column shopping_cart_items.item_id is 'Идентификатор товара';
  157. comment on column shopping_cart_items.item_price is 'Цена товара в корзине';
  158. comment on column shopping_cart_items.item_qty is 'Количество товара в корзине';
  159.  
  160. create table if not exists order_statuses
  161. (
  162.     id   bigserial primary key,
  163.     name text not null
  164. );
  165. create unique index uq__order_statuses__name on order_statuses (name);
  166. comment on table order_statuses is 'Статусы заказа';
  167. comment on column order_statuses.id is 'Идентификатор статуса';
  168. comment on column order_statuses.name is 'Название статуса';
  169.  
  170. create table if not exists orders
  171. (
  172.     id         uuid        default gen_random_uuid() primary key,
  173.     user_id    bigint                                                  not null,
  174.     status_id  bigint                                                  not null,
  175.     created_at timestamptz default timezone('utc', now())::timestamptz not null,
  176.     updated_at timestamptz default timezone('utc', now())::timestamptz not null,
  177.  
  178.     constraint fk__orders__users foreign key (user_id) references users (id),
  179.     constraint fk__orders__order_statuses foreign key (status_id) references order_statuses (id)
  180. );
  181. comment on table orders is 'Заказы';
  182. comment on column orders.id is 'Идентификатор заказа';
  183. comment on column orders.user_id is 'Идентификатор пользоавтеля-заказчика';
  184. comment on column orders.status_id is 'Идентификатор статуса заказа';
  185. comment on column orders.created_at is 'Дата и время создания записи';
  186. comment on column orders.updated_at is 'Дата и время обновления записи';
  187.  
  188. create table if not exists order_details
  189. (
  190.     order_id   uuid                                                    not null,
  191.     item_id    bigint                                                  not null,
  192.     item_price decimal                                                 not null,
  193.     item_qty   integer                                                 not null,
  194.     created_at timestamptz default timezone('utc', now())::timestamptz not null,
  195.     updated_at timestamptz default timezone('utc', now())::timestamptz not null,
  196.  
  197.     primary key (order_id, item_id),
  198.     constraint fk__order_details__orders foreign key (order_id) references orders (id),
  199.     constraint fk__order_details__items foreign key (item_id) references items (id)
  200. );
  201. comment on table order_details is 'Детали заказа';
  202. comment on column order_details.order_id is 'Идентификатор заказа';
  203. comment on column order_details.item_id is 'Идентификатор товара';
  204. comment on column order_details.item_price is 'Цена товара в заказе';
  205. comment on column order_details.item_qty is 'Количество товара в заказе';
  206. comment on column order_details.created_at is 'Дата и время создания записи';
  207. comment on column order_details.updated_at is 'Дата и время обновления записи';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement