Added transaction feature, fixed some mistakes

This commit is contained in:
2026-04-11 11:12:54 +03:00
parent 6872563c62
commit 545b05d5a0
37 changed files with 2509 additions and 115 deletions
@@ -1,7 +1,7 @@
CREATE TABLE users
(
id BIGSERIAL PRIMARY KEY,
telegram_id BIGINT UNIQUE NOT NULL,
telegram_id BIGINT UNIQUE,
username TEXT,
first_name TEXT NOT NULL,
last_name TEXT,
@@ -3,7 +3,7 @@ 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,
telegram_chat_id BIGINT,
telegram_chat_name TEXT,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
@@ -1,2 +0,0 @@
DROP TABLE IF EXISTS threads;
DROP TYPE IF EXISTS thread_type;
@@ -1,19 +0,0 @@
CREATE TABLE family_threads
(
id BIGSERIAL PRIMARY KEY,
family_id BIGINT NOT NULL REFERENCES families (id) ON DELETE CASCADE,
type TEXT 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 family_threads (family_id, type) WHERE is_system = TRUE;
CREATE INDEX idx_threads_family_id ON family_threads (family_id);
CREATE INDEX idx_threads_family_type ON family_threads (family_id, type);
@@ -1 +1,2 @@
DROP TABLE receipts;
DROP TABLE IF EXISTS receipts;
DROP TABLE IF EXISTS transactions;
@@ -1,6 +1,25 @@
CREATE TABLE transactions
(
id BIGSERIAL PRIMARY KEY,
family_id BIGINT NOT NULL REFERENCES families (id) ON DELETE CASCADE,
description TEXT,
type TEXT NOT NULL,
datetime TIMESTAMP NOT NULL,
category TEXT NOT NULL,
amount NUMERIC(14, 2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
created_by BIGINT NOT NULL REFERENCES users (id) ON DELETE RESTRICT
);
CREATE INDEX idx_transactions_family_id ON transactions (family_id);
CREATE INDEX idx_transactions_datetime ON transactions (datetime);
CREATE INDEX idx_transactions_created_by ON transactions (created_by);
CREATE INDEX idx_transactions_family_datetime ON transactions (family_id, datetime DESC);
CREATE TABLE receipts
(
id BIGSERIAL PRIMARY KEY,
transaction_id BIGINT UNIQUE REFERENCES transactions (id) ON DELETE SET NULL,
receipt_number TEXT NOT NULL UNIQUE,
ui TEXT NOT NULL,
status INTEGER NOT NULL,
@@ -29,7 +48,8 @@ CREATE TABLE receipts
skno_number TEXT,
unp TEXT,
success TEXT,
created_at TIMESTAMP DEFAULT NOW()
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_receipts_issued_at ON receipts(issued_at);
CREATE INDEX idx_receipts_issued_at ON receipts (issued_at);
CREATE INDEX idx_receipts_transaction_id ON receipts (transaction_id);