Загрузить файлы в «works/daily/10-11-2026»

This commit is contained in:
2026-11-19 06:10:08 +00:00
parent bf8ae804f6
commit 1250a3c15b
3 changed files with 274 additions and 0 deletions
+136
View File
@@ -0,0 +1,136 @@
-- Основная таблица с данными
create table staging_raw_catcafe (
row_id int,
visit_id int,
visit_date date,
visitor_first_name text,
visitor_last_name text,
visitor_phone text,
visitor_email text,
payment_method text,
cat_name text,
cat_breed text,
cat_age_months int,
cat_color text,
cat_arrival_date date,
cat_adoption_date date,
adopter_phone text,
employee_first_name text,
employee_last_name text,
employee_position text,
employee_salary int,
menu_item_name text,
menu_category text,
menu_item_price int,
quantity int
);
-- Коллекция различных пород
create table breeds(
breed_id int generated always as identity primary key,
breed_name text not null unique
);
-- Как ни странно... коллекция окрасов
create table colors(
color_id int generated always as identity primary key,
color_name text not null unique
);
-- Должности
create table positions(
position_id int generated always as identity primary key,
position_name text not null unique
);
-- Категории блюд
create table categories(
category_id int generated always as identity primary key,
category_name text not null unique
);
create table payment_methods(
payment_method_id int generated always as identity primary key,
payment_method_name text not null unique
);
-- Коты. Имеют кличку, породу, возраст, окрас, дату поступления в кафе и (опционально) дату усыновления.
create table cats(
cat_id int generated always as identity primary key,
cat_name text not null,
cat_breed_id int not null references breeds(breed_id),
cat_color_id int not null references colors(color_id),
cat_age_months int not null,
cat_arrival_date date not null,
-- cat_adoption_id int references adoptions(adoption_id),
unique (cat_name, cat_breed_id, cat_color_id, cat_age_months, cat_arrival_date)
);
-- Посетители
create table visitors(
visitor_id int generated always as identity primary key,
visitor_first_name text not null,
visitor_last_name text not null,
visitor_phone text not null,
visitor_email text not null,
unique (visitor_first_name, visitor_last_name, visitor_phone, visitor_email)
);
-- Усыновление. Некоторые коты забираются посетителями домой — с фиксацией даты и усыновителя. Кот может быть усыновлён только один раз.
create table adoptions(
adoption_id int generated always as identity primary key,
adoption_cat_id int not null references cats(cat_id),
adoption_date date not null,
adoption_phone text not null
);
-- Сотрудники. Имеют должность и оклад; часть сотрудников (уборщик, администратор) не участвует в обслуживании визитов.
create table employees(
employee_id int generated always as identity primary key,
employee_first_name text not null,
employee_last_name text not null,
employee_position_id int not null references positions(position_id),
employee_salary int not null,
unique (employee_first_name, employee_last_name, employee_position_id, employee_salary)
);
-- Меню. Каждое блюдо имеет уникальное название, категорию и цену.
create table menu_items(
menu_item_id int generated always as identity primary key,
menu_item_name text not null,
menu_item_category_id int references categories(category_id),
menu_item_price int not null,
unique (menu_item_name, menu_item_category_id, menu_item_price)
);
-- Визит. Посетитель приходит в кафе, его обслуживает сотрудник (бариста / официант / менеджер), выбирается метод оплаты (карта / наличные / СБП).
create table visits(
visit_id int generated always as identity primary key,
visit_visitor_id int not null references visitors(visitor_id),
visit_date date not null,
visit_employee_id int not null references employees(employee_id),
visit_payment_method_id int not null references payment_methods(payment_method_id)
);
-- Заказ. За визит оформляются позиции заказа из меню (напитки, десерты, выпечка, еда); каждая позиция имеет количество; цена фиксируется на момент заказа.
create table order_item(
order_item_id int generated always as identity primary key,
order_visitor_id int not null references visitors(visitor_id),
order_item_product_id int not null references menu_items(menu_item_id),
order_item_quantity int not null
);
-- Общение с котами. За визит посетитель может провзаимодействовать с одним или несколькими котами (связь «многие-ко-многим»).
create table visit_cats(
visit_cats_id int generated always as identity primary key,
visit_cats_visit_id int not null references visits(visit_id),
visit_cats_visitor_id int not null references visitors(visitor_id),
visit_cats_cat_id int not null references cats(cat_id)
);