commit ca5259c638453b9db0ab376d58172554482bfceb Author: Alexander Zhirov Date: Mon May 29 17:40:53 2023 +0300 база данных diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ec69ee --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/database/volumes-data diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f1fc2b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# daster + +Управление диалпланом diff --git a/database/docker-compose.yml b/database/docker-compose.yml new file mode 100644 index 0000000..f62ec4c --- /dev/null +++ b/database/docker-compose.yml @@ -0,0 +1,17 @@ +services: + postgres: + image: registry.zhirov.kz/postgresql-15.3:alpine-3.18.0-amd64 + container_name: postgres-asterisk + restart: always + environment: + POSTGRES_DB: asterisk + POSTGRES_USER: asterisk + POSTGRES_PASSWORD: asterisk + PGTZ: Europe/Moscow + TZ: Europe/Moscow + ports: + - 5432:5432 + volumes: + - ./volumes-data:/var/lib/postgresql/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro diff --git a/database/script.sql b/database/script.sql new file mode 100644 index 0000000..63ba543 --- /dev/null +++ b/database/script.sql @@ -0,0 +1,62 @@ +create table if not exists "groups" ( + "name" varchar(20) not null, + "comment" varchar(100) default null, + constraint groups_pk primary key ("name") +); + +insert into "groups" ("name", "comment") + values + ('general', 'Общие контакты'), + ('work', 'Рабочие контакты'), + ('personal', 'Личные контакты'); + +create table if not exists lists ( + "name" varchar(20) not null, + "comment" varchar(100) default null, + constraint lists_pk primary key ("name") +); + +insert into lists ("name", "comment") + values + ('general', 'Общий список'), + ('whitelist', 'Белый список'), + ('blacklist', 'Черный список'); + +create table if not exists numbers ( + "number" varchar(12) not null, + "group" varchar(20) not null default 'general', + list varchar(20) not null default 'general', + all_cc int not null default 0, + white_cc int not null default 0, + black_cc int not null default 0, + "comment" varchar(100) default null, + constraint numbers_pk primary key ("number"), + foreign key ("group") references "groups" ("name") on delete set null on update cascade, + foreign key (list) references lists ("name") on delete set null on update cascade +); + +create table if not exists sms ( + id bigserial not null, + "date" timestamp not null default NOW(), + "to" varchar(12) not null, + "from" varchar(12) not null, + "text" text not null, + constraint sms_pk primary key (id) +); + +create table if not exists ussd ( + id bigserial not null, + "date" timestamp not null default NOW(), + "to" varchar(12) not null, + "type" smallint not null, + "text" text not null, + constraint ussd_pk primary key (id) +); + +create table if not exists "server" ( + address varchar(50) not null, + transparent_mode bool not null default false, + internal_number varchar(12) not null, + external_number varchar(12) not null, + constraint server_pk primary key (address) +);