База данных адаптирована под актуальный бизнес-процесс
Этот коммит содержится в:
родитель
8bc44bd59d
Коммит
b0edb71ad4
59
database.sql
59
database.sql
@ -1,18 +1,27 @@
|
|||||||
|
create type user_role as enum (
|
||||||
|
'user',
|
||||||
|
'moderator',
|
||||||
|
'admin'
|
||||||
|
);
|
||||||
|
|
||||||
create table users (
|
create table users (
|
||||||
id bigserial not null,
|
id bigserial not null,
|
||||||
telegram_user_id bigint not null,
|
telegram_user_id bigint not null,
|
||||||
first_name character varying (64) not null,
|
first_name character varying (64) not null,
|
||||||
last_name character varying (64),
|
last_name character varying (64),
|
||||||
username character varying (32),
|
username character varying (32),
|
||||||
|
role user_role,
|
||||||
primary key (id),
|
primary key (id),
|
||||||
unique (telegram_user_id)
|
unique (telegram_user_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table poll_schemas (
|
create table poll_schemas (
|
||||||
id bigserial not null,
|
id bigserial not null,
|
||||||
|
owner_id bigint not null,
|
||||||
name character varying (32) not null,
|
name character varying (32) not null,
|
||||||
question character varying (255) not null,
|
question character varying (255) not null,
|
||||||
primary key (id),
|
primary key (id),
|
||||||
|
foreign key (owner_id) references users on delete cascade on update cascade,
|
||||||
unique (name)
|
unique (name)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -27,19 +36,57 @@ create table poll_options (
|
|||||||
unique (poll_schema_id, ordinal)
|
unique (poll_schema_id, ordinal)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table polls (
|
create table messages (
|
||||||
id bigserial not null,
|
id bigserial not null,
|
||||||
telegram_message_id bigint not null,
|
telegram_message_id bigint not null,
|
||||||
|
created_at timestamp default now() not null,
|
||||||
|
primary key (id),
|
||||||
|
unique (telegram_message_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table text_messages (
|
||||||
|
text character varying (4096) not null
|
||||||
|
) inherits (messages);
|
||||||
|
|
||||||
|
create table poll_messages (
|
||||||
telegram_poll_id text not null,
|
telegram_poll_id text not null,
|
||||||
poll_schema_id bigint not null,
|
poll_schema_id bigint not null,
|
||||||
created_at timestamp default now() not null,
|
|
||||||
is_complete boolean default false not null,
|
is_complete boolean default false not null,
|
||||||
primary key (id),
|
|
||||||
foreign key (poll_schema_id) references poll_schemas on delete cascade on update cascade,
|
|
||||||
unique (telegram_message_id),
|
|
||||||
unique (telegram_poll_id)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table media_messages () inherits (messages);
|
||||||
|
|
||||||
|
create table media_message_files (
|
||||||
|
id bigserial not null,
|
||||||
|
media_message_id bigint not null,
|
||||||
|
name character varying (256) not null,
|
||||||
|
caption character varying (4096) not null,
|
||||||
|
primary key (id),
|
||||||
|
foreign key (media_message_id) references media_messages on delete cascade on update cascade
|
||||||
|
);
|
||||||
|
|
||||||
|
create table contact_messages (
|
||||||
|
phone_number character varying (16) not null,
|
||||||
|
first_name character varying (32) not null
|
||||||
|
) inherits (messages);
|
||||||
|
|
||||||
|
create table dice_messages (
|
||||||
|
value smallint not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- create table polls (
|
||||||
|
-- id bigserial not null,
|
||||||
|
-- telegram_message_id bigint not null,
|
||||||
|
-- telegram_poll_id text not null,
|
||||||
|
-- poll_schema_id bigint not null,
|
||||||
|
-- created_at timestamp default now() not null,
|
||||||
|
-- is_complete boolean default false not null,
|
||||||
|
-- primary key (id),
|
||||||
|
-- foreign key (poll_schema_id) references poll_schemas on delete cascade on update cascade,
|
||||||
|
-- unique (telegram_message_id),
|
||||||
|
-- unique (telegram_poll_id)
|
||||||
|
-- );
|
||||||
|
|
||||||
create table poll_answers (
|
create table poll_answers (
|
||||||
id bigserial not null,
|
id bigserial not null,
|
||||||
poll_id bigint not null,
|
poll_id bigint not null,
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user