recurrents
This commit is contained in:
21
src/main/resources/db/migration/V24__.sql
Normal file
21
src/main/resources/db/migration/V24__.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
create table if not exists finance.bot_states
|
||||
(
|
||||
user_id integer primary key,
|
||||
state_code varchar not null
|
||||
);
|
||||
|
||||
create table if not exists finance.bot_states_data
|
||||
(
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
user_id integer not null,
|
||||
data_code varchar(255) not null,
|
||||
data_value varchar(255) not null,
|
||||
CONSTRAINT pk_bot_states_data PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE finance.bot_states
|
||||
ADD CONSTRAINT FK_STATE_ON_USER FOREIGN KEY (user_id) REFERENCES finance.users (id);
|
||||
|
||||
ALTER TABLE finance.bot_states
|
||||
ADD CONSTRAINT FK_STATE_DATA_ON_USER FOREIGN KEY (user_id) REFERENCES finance.users (id);
|
||||
|
||||
3
src/main/resources/db/migration/V25__.sql
Normal file
3
src/main/resources/db/migration/V25__.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- уникальное ограничение под ON CONFLICT (user_id, data_code)
|
||||
ALTER TABLE finance.bot_states_data
|
||||
ADD CONSTRAINT ux_bot_states_data_user_code UNIQUE (user_id, data_code);
|
||||
3
src/main/resources/db/migration/V26__.sql
Normal file
3
src/main/resources/db/migration/V26__.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- уникальное ограничение под ON CONFLICT (user_id, data_code)
|
||||
ALTER TABLE finance.transactions
|
||||
ALTER COLUMN category_id DROP NOT NULL;
|
||||
19
src/main/resources/db/migration/V27__.sql
Normal file
19
src/main/resources/db/migration/V27__.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Очередь классификации категорий
|
||||
CREATE TABLE IF NOT EXISTS finance.category_jobs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tx_id INT NOT NULL UNIQUE, -- одна задача на транзакцию
|
||||
status TEXT NOT NULL DEFAULT 'NEW', -- NEW | PROCESSING | DONE | FAILED
|
||||
attempts INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
started_at TIMESTAMPTZ,
|
||||
finished_at TIMESTAMPTZ,
|
||||
last_error TEXT
|
||||
);
|
||||
|
||||
-- Быстрые выборки по статусу
|
||||
CREATE INDEX IF NOT EXISTS ix_category_jobs_status ON finance.category_jobs(status);
|
||||
|
||||
-- (опционально) защита от «зависших» задач
|
||||
CREATE INDEX IF NOT EXISTS ix_category_jobs_processing_time
|
||||
ON finance.category_jobs(started_at)
|
||||
WHERE status = 'PROCESSING';
|
||||
3
src/main/resources/db/migration/V28__.sql
Normal file
3
src/main/resources/db/migration/V28__.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
alter table finance.transactions
|
||||
add column tg_chat_id bigint null,
|
||||
add column tg_message_id bigint null;
|
||||
3
src/main/resources/db/migration/V29__.sql
Normal file
3
src/main/resources/db/migration/V29__.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
alter table finance.category_jobs
|
||||
add column tg_chat_id bigint null,
|
||||
add column tg_message_id bigint null;
|
||||
5
src/main/resources/db/migration/V30__.sql
Normal file
5
src/main/resources/db/migration/V30__.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE finance.recurrent_operations
|
||||
ADD CONSTRAINT recurrent_operations_pk PRIMARY KEY (id);
|
||||
alter table finance.transactions
|
||||
add column recurrent_id integer null,
|
||||
ADD CONSTRAINT FK_RECURRENTS FOREIGN KEY (recurrent_id) REFERENCES finance.recurrent_operations (id);
|
||||
Reference in New Issue
Block a user