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);

