Renamed and updated project.

This commit is contained in:
2026-01-27 20:27:06 +03:00
parent e6dc59c266
commit 2ee1837fcc
38 changed files with 499 additions and 235 deletions
+1
View File
@@ -0,0 +1 @@
DROP TABLE IF EXISTS users;
+13
View File
@@ -0,0 +1,13 @@
CREATE TABLE users
(
id BIGSERIAL PRIMARY KEY,
telegram_id BIGINT UNIQUE NOT NULL,
username TEXT,
first_name TEXT NOT NULL,
last_name TEXT,
language_code TEXT,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_users_telegram_id ON users (telegram_id);
@@ -0,0 +1 @@
DROP TABLE IF EXISTS telegram_chats;
@@ -0,0 +1,9 @@
CREATE TABLE telegram_chats
(
id BIGSERIAL PRIMARY KEY,
telegram_id BIGINT UNIQUE NOT NULL,
title TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_telegram_chats_telegram_id ON telegram_chats (telegram_id);
-2
View File
@@ -1,2 +0,0 @@
DROP INDEX idx_positions_receipt_id;
DROP INDEX idx_receipts_issued_at;
-2
View File
@@ -1,2 +0,0 @@
CREATE INDEX idx_receipts_issued_at ON receipts(issued_at);
CREATE INDEX idx_positions_receipt_id ON positions(receipt_id);
@@ -0,0 +1 @@
DROP TABLE IF EXISTS families;
+12
View File
@@ -0,0 +1,12 @@
CREATE TABLE families
(
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
owner_id BIGINT NOT NULL REFERENCES users (id),
telegram_chat_id BIGINT NOT NULL UNIQUE REFERENCES telegram_chats (id),
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_families_owner_id ON families (owner_id);
CREATE UNIQUE INDEX idx_families_chat_id ON families (telegram_chat_id);
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS family_members;
DROP TYPE IF EXISTS family_role;
@@ -0,0 +1,26 @@
CREATE TYPE family_role AS ENUM (
'owner',
'admin',
'member',
'child'
);
CREATE TABLE family_members
(
id BIGSERIAL PRIMARY KEY,
family_id BIGINT NOT NULL REFERENCES families (id) ON DELETE CASCADE,
user_id BIGINT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
role family_role NOT NULL DEFAULT 'member',
joined_at TIMESTAMP NOT NULL DEFAULT NOW(),
UNIQUE (family_id, user_id)
);
-- быстрый поиск всех членов семьи
CREATE INDEX idx_family_members_family_id ON family_members (family_id);
-- быстрый поиск всех семей пользователя
CREATE INDEX idx_family_members_user_id ON family_members (user_id);
-- composite для частых join’ов
CREATE INDEX idx_family_members_user_family ON family_members (user_id, family_id);
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS threads;
DROP TYPE IF EXISTS thread_type;
+27
View File
@@ -0,0 +1,27 @@
CREATE TYPE thread_type AS ENUM (
'expenses',
'movies',
'schedule',
'recipes',
'custom'
);
CREATE TABLE threads
(
id BIGSERIAL PRIMARY KEY,
family_id BIGINT NOT NULL REFERENCES families (id) ON DELETE CASCADE,
type thread_type NOT NULL,
title TEXT NOT NULL,
telegram_topic_id BIGINT NOT NULL,
is_system BOOLEAN NOT NULL DEFAULT FALSE,
created_by BIGINT NOT NULL REFERENCES users (id),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
UNIQUE (family_id, telegram_topic_id)
);
CREATE UNIQUE INDEX idx_unique_system_threads ON threads (family_id, type) WHERE is_system = TRUE;
CREATE INDEX idx_threads_family_id ON threads (family_id);
CREATE INDEX idx_threads_family_type ON threads(family_id, type);
@@ -1,52 +1,35 @@
CREATE TABLE receipts
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
-- основные поля
id BIGSERIAL PRIMARY KEY,
receipt_number TEXT NOT NULL UNIQUE,
ui TEXT NOT NULL,
status INTEGER NOT NULL,
issued_at TIMESTAMP NOT NULL,
-- суммы
total_amount REAL NOT NULL,
payment_amount REAL NOT NULL,
cash_amount REAL NOT NULL,
another_amount REAL NOT NULL,
clearing_amount REAL NOT NULL,
margin REAL NOT NULL,
currency TEXT NOT NULL,
payment_type INTEGER NOT NULL,
-- касса / продавец
cashbox_number INTEGER NOT NULL,
cashier TEXT,
-- организация / адрес
name_spd TEXT,
name_to TEXT,
name_np TEXT,
type_np TEXT,
street_to TEXT,
house_to TEXT,
-- SOATO (nullable)
kod_soato TEXT,
oblast_soato TEXT,
rayon_soato TEXT,
selsovet_soato TEXT,
-- прочее
doc_num TEXT,
skno_number TEXT,
unp TEXT,
success TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
created_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_receipts_issued_at ON receipts(issued_at);
@@ -1,25 +1,19 @@
CREATE TABLE positions
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
receipt_id INTEGER NOT NULL,
id BIGSERIAL PRIMARY KEY,
receipt_id BIGINT NOT NULL,
section_number TEXT,
gtin_code TEXT,
product_name TEXT NOT NULL,
product_count REAL NOT NULL,
amount REAL NOT NULL,
discount REAL,
surcharge REAL,
tag TEXT,
marking_code TEXT,
ukz_code TEXT,
FOREIGN KEY (receipt_id)
REFERENCES receipts (id)
ON DELETE CASCADE
FOREIGN KEY (receipt_id) REFERENCES receipts (id) ON DELETE CASCADE
);
CREATE INDEX idx_positions_receipt_id ON positions (receipt_id);