-
Notifications
You must be signed in to change notification settings - Fork 0
First‐start
-
Подготовка базы данных
Если у вас еще нет подготовленной базы данных, используйте
rais db:create db:migrate
из проекта Web-платформы или выполнить скрипт для создания DDL в вашей PostgreSQL:
Показать SQL-скрипт
-- DROP SCHEMA public;
CREATE SCHEMA public AUTHORIZATION postgres;
-- DROP SEQUENCE public.buildings_id_seq;
CREATE SEQUENCE public.buildings_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.buildings_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.buildings_id_seq TO postgres;
-- DROP SEQUENCE public.channels_id_seq;
CREATE SEQUENCE public.channels_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.channels_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.channels_id_seq TO postgres;
-- DROP SEQUENCE public.device_components_id_seq;
CREATE SEQUENCE public.device_components_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.device_components_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.device_components_id_seq TO postgres;
-- DROP SEQUENCE public.device_models_id_seq;
CREATE SEQUENCE public.device_models_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.device_models_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.device_models_id_seq TO postgres;
-- DROP SEQUENCE public.device_reg_groups_id_seq;
CREATE SEQUENCE public.device_reg_groups_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.device_reg_groups_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.device_reg_groups_id_seq TO postgres;
-- DROP SEQUENCE public.devices_id_seq;
CREATE SEQUENCE public.devices_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.devices_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.devices_id_seq TO postgres;
-- DROP SEQUENCE public.divisions_id_seq;
CREATE SEQUENCE public.divisions_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.divisions_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.divisions_id_seq TO postgres;
-- DROP SEQUENCE public.histories_id_seq;
CREATE SEQUENCE public.histories_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.histories_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.histories_id_seq TO postgres;
-- DROP SEQUENCE public.inspections_id_seq;
CREATE SEQUENCE public.inspections_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.inspections_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.inspections_id_seq TO postgres;
-- DROP SEQUENCE public.manufacturers_id_seq;
CREATE SEQUENCE public.manufacturers_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.manufacturers_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.manufacturers_id_seq TO postgres;
-- DROP SEQUENCE public.measurement_classes_id_seq;
CREATE SEQUENCE public.measurement_classes_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.measurement_classes_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.measurement_classes_id_seq TO postgres;
-- DROP SEQUENCE public.measurement_groups_id_seq;
CREATE SEQUENCE public.measurement_groups_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.measurement_groups_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.measurement_groups_id_seq TO postgres;
-- DROP SEQUENCE public.organizations_id_seq;
CREATE SEQUENCE public.organizations_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.organizations_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.organizations_id_seq TO postgres;
-- DROP SEQUENCE public.posts_id_seq;
CREATE SEQUENCE public.posts_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.posts_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.posts_id_seq TO postgres;
-- DROP SEQUENCE public.rooms_id_seq;
CREATE SEQUENCE public.rooms_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.rooms_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.rooms_id_seq TO postgres;
-- DROP SEQUENCE public.servers_id_seq;
CREATE SEQUENCE public.servers_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.servers_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.servers_id_seq TO postgres;
-- DROP SEQUENCE public.services_id_seq;
CREATE SEQUENCE public.services_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.services_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.services_id_seq TO postgres;
-- DROP SEQUENCE public.supplementary_kits_id_seq;
CREATE SEQUENCE public.supplementary_kits_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.supplementary_kits_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.supplementary_kits_id_seq TO postgres;
-- DROP SEQUENCE public.users_id_seq;
CREATE SEQUENCE public.users_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
NO CYCLE;
-- Permissions
ALTER SEQUENCE public.users_id_seq OWNER TO postgres;
GRANT ALL ON SEQUENCE public.users_id_seq TO postgres;
-- public.ar_internal_metadata definition
-- Drop table
-- DROP TABLE public.ar_internal_metadata;
CREATE TABLE public.ar_internal_metadata (
"key" varchar NOT NULL,
value varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key)
);
-- Permissions
ALTER TABLE public.ar_internal_metadata OWNER TO postgres;
GRANT ALL ON TABLE public.ar_internal_metadata TO postgres;
-- public.device_reg_groups definition
-- Drop table
-- DROP TABLE public.device_reg_groups;
CREATE TABLE public.device_reg_groups (
id bigserial NOT NULL,
"name" varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT device_reg_groups_pkey PRIMARY KEY (id)
);
-- Permissions
ALTER TABLE public.device_reg_groups OWNER TO postgres;
GRANT ALL ON TABLE public.device_reg_groups TO postgres;
-- public.manufacturers definition
-- Drop table
-- DROP TABLE public.manufacturers;
CREATE TABLE public.manufacturers (
id bigserial NOT NULL,
"name" varchar NULL,
adress varchar NULL,
phone varchar NULL,
email varchar NULL,
site_url varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT manufacturers_pkey PRIMARY KEY (id)
);
-- Permissions
ALTER TABLE public.manufacturers OWNER TO postgres;
GRANT ALL ON TABLE public.manufacturers TO postgres;
-- public.measurement_groups definition
-- Drop table
-- DROP TABLE public.measurement_groups;
CREATE TABLE public.measurement_groups (
id bigserial NOT NULL,
"name" varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT measurement_groups_pkey PRIMARY KEY (id)
);
-- Permissions
ALTER TABLE public.measurement_groups OWNER TO postgres;
GRANT ALL ON TABLE public.measurement_groups TO postgres;
-- public.organizations definition
-- Drop table
-- DROP TABLE public.organizations;
CREATE TABLE public.organizations (
id bigserial NOT NULL,
"name" varchar NULL,
full_address varchar NULL,
zip_code varchar NULL,
phone varchar NULL,
fax varchar NULL,
email varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT organizations_pkey PRIMARY KEY (id)
);
-- Permissions
ALTER TABLE public.organizations OWNER TO postgres;
GRANT ALL ON TABLE public.organizations TO postgres;
-- public.schema_migrations definition
-- Drop table
-- DROP TABLE public.schema_migrations;
CREATE TABLE public.schema_migrations (
"version" varchar NOT NULL,
CONSTRAINT schema_migrations_pkey PRIMARY KEY (version)
);
-- Permissions
ALTER TABLE public.schema_migrations OWNER TO postgres;
GRANT ALL ON TABLE public.schema_migrations TO postgres;
-- public.supplementary_kits definition
-- Drop table
-- DROP TABLE public.supplementary_kits;
CREATE TABLE public.supplementary_kits (
id bigserial NOT NULL,
"name" varchar NULL,
serial_id varchar NULL,
description varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT supplementary_kits_pkey PRIMARY KEY (id)
);
-- Permissions
ALTER TABLE public.supplementary_kits OWNER TO postgres;
GRANT ALL ON TABLE public.supplementary_kits TO postgres;
-- public.buildings definition
-- Drop table
-- DROP TABLE public.buildings;
CREATE TABLE public.buildings (
id bigserial NOT NULL,
"name" varchar NULL,
organization_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT buildings_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_6c5ed8c27f FOREIGN KEY (organization_id) REFERENCES public.organizations(id)
);
CREATE INDEX index_buildings_on_organization_id ON public.buildings USING btree (organization_id);
-- Permissions
ALTER TABLE public.buildings OWNER TO postgres;
GRANT ALL ON TABLE public.buildings TO postgres;
-- public.device_components definition
-- Drop table
-- DROP TABLE public.device_components;
CREATE TABLE public.device_components (
id bigserial NOT NULL,
supplementary_kit_id int8 NULL,
serial_id varchar NULL,
"name" varchar NULL,
measurement_min float8 NULL,
measurement_max float8 NULL,
measuring_unit varchar NULL,
description text NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT device_components_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_31b46de29b FOREIGN KEY (supplementary_kit_id) REFERENCES public.supplementary_kits(id)
);
CREATE INDEX index_device_components_on_supplementary_kit_id ON public.device_components USING btree (supplementary_kit_id);
-- Permissions
ALTER TABLE public.device_components OWNER TO postgres;
GRANT ALL ON TABLE public.device_components TO postgres;
-- public.divisions definition
-- Drop table
-- DROP TABLE public.divisions;
CREATE TABLE public.divisions (
id bigserial NOT NULL,
"name" varchar NULL,
organization_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT divisions_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_648c512956 FOREIGN KEY (organization_id) REFERENCES public.organizations(id)
);
CREATE INDEX index_divisions_on_organization_id ON public.divisions USING btree (organization_id);
-- Permissions
ALTER TABLE public.divisions OWNER TO postgres;
GRANT ALL ON TABLE public.divisions TO postgres;
-- public.measurement_classes definition
-- Drop table
-- DROP TABLE public.measurement_classes;
CREATE TABLE public.measurement_classes (
id bigserial NOT NULL,
"name" varchar NULL,
measurement_group_id int8 NOT NULL,
arms_device_type int4 NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT measurement_classes_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_45494ba51a FOREIGN KEY (measurement_group_id) REFERENCES public.measurement_groups(id)
);
CREATE INDEX index_measurement_classes_on_measurement_group_id ON public.measurement_classes USING btree (measurement_group_id);
-- Permissions
ALTER TABLE public.measurement_classes OWNER TO postgres;
GRANT ALL ON TABLE public.measurement_classes TO postgres;
-- public.rooms definition
-- Drop table
-- DROP TABLE public.rooms;
CREATE TABLE public.rooms (
id bigserial NOT NULL,
"name" varchar NULL,
building_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT rooms_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_a3957b23a8 FOREIGN KEY (building_id) REFERENCES public.buildings(id)
);
CREATE INDEX index_rooms_on_building_id ON public.rooms USING btree (building_id);
-- Permissions
ALTER TABLE public.rooms OWNER TO postgres;
GRANT ALL ON TABLE public.rooms TO postgres;
-- public.services definition
-- Drop table
-- DROP TABLE public.services;
CREATE TABLE public.services (
id bigserial NOT NULL,
"name" varchar NULL,
division_id int8 NOT NULL,
organization_id int8 NOT NULL,
building_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT services_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_2e9f369e43 FOREIGN KEY (organization_id) REFERENCES public.organizations(id),
CONSTRAINT fk_rails_76634691db FOREIGN KEY (building_id) REFERENCES public.buildings(id),
CONSTRAINT fk_rails_f50c4560d9 FOREIGN KEY (division_id) REFERENCES public.divisions(id)
);
CREATE INDEX index_services_on_building_id ON public.services USING btree (building_id);
CREATE INDEX index_services_on_division_id ON public.services USING btree (division_id);
CREATE INDEX index_services_on_organization_id ON public.services USING btree (organization_id);
-- Permissions
ALTER TABLE public.services OWNER TO postgres;
GRANT ALL ON TABLE public.services TO postgres;
-- public.users definition
-- Drop table
-- DROP TABLE public.users;
CREATE TABLE public.users (
id bigserial NOT NULL,
tabel_id int4 NOT NULL,
first_name varchar NULL,
second_name varchar NULL,
last_name varchar NULL,
phone varchar NULL,
avatar_url varchar NULL,
service_id int8 NOT NULL,
email varchar NULL DEFAULT ''::character varying,
encrypted_password varchar NOT NULL DEFAULT ''::character varying,
reset_password_token varchar NULL,
reset_password_sent_at timestamp(6) NULL,
remember_created_at timestamp(6) NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
timezone varchar NOT NULL DEFAULT 'UTC'::character varying,
"role" varchar NOT NULL DEFAULT 'default'::character varying,
CONSTRAINT users_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_093eb6ba73 FOREIGN KEY (service_id) REFERENCES public.services(id)
);
CREATE UNIQUE INDEX index_users_on_reset_password_token ON public.users USING btree (reset_password_token);
CREATE INDEX index_users_on_service_id ON public.users USING btree (service_id);
CREATE UNIQUE INDEX index_users_on_tabel_id ON public.users USING btree (tabel_id);
-- Permissions
ALTER TABLE public.users OWNER TO postgres;
GRANT ALL ON TABLE public.users TO postgres;
-- public.device_models definition
-- Drop table
-- DROP TABLE public.device_models;
CREATE TABLE public.device_models (
id bigserial NOT NULL,
"name" varchar NULL,
measurement_group_id int8 NOT NULL,
measurement_class_id int8 NOT NULL,
measuring_unit varchar NULL,
safety_class varchar NULL,
accuracy_class float8 NULL,
measurement_sensitivity float8 NULL,
measurement_min float8 NULL,
measurement_max float8 NULL,
manufacturer_id int8 NOT NULL,
is_complete_device bool NULL,
is_tape_rolling_mechanism bool NULL,
doc_url varchar NULL,
image_url varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
calibration_min float8 NULL,
calibration_max float8 NULL,
CONSTRAINT device_models_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_806ab71b20 FOREIGN KEY (manufacturer_id) REFERENCES public.manufacturers(id),
CONSTRAINT fk_rails_cb28d0e4ea FOREIGN KEY (measurement_group_id) REFERENCES public.measurement_groups(id),
CONSTRAINT fk_rails_ec1705823a FOREIGN KEY (measurement_class_id) REFERENCES public.measurement_classes(id)
);
CREATE INDEX index_device_models_on_manufacturer_id ON public.device_models USING btree (manufacturer_id);
CREATE INDEX index_device_models_on_measurement_class_id ON public.device_models USING btree (measurement_class_id);
CREATE INDEX index_device_models_on_measurement_group_id ON public.device_models USING btree (measurement_group_id);
-- Permissions
ALTER TABLE public.device_models OWNER TO postgres;
GRANT ALL ON TABLE public.device_models TO postgres;
-- public.devices definition
-- Drop table
-- DROP TABLE public.devices;
CREATE TABLE public.devices (
id bigserial NOT NULL,
inventory_id int4 NULL,
serial_id varchar NULL,
tabel_id int4 NULL,
device_model_id int8 NOT NULL,
device_reg_group_id int8 NOT NULL,
year_of_production int4 NULL,
year_of_commissioning int4 NULL,
supplementary_kit_id int8 NULL,
service_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
room_id int8 NULL,
inspection_expiration_status varchar NOT NULL DEFAULT 'prepare_to_inspection'::character varying,
status varchar NOT NULL DEFAULT 'in_stock'::character varying,
CONSTRAINT devices_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_1ac96c8753 FOREIGN KEY (device_reg_group_id) REFERENCES public.device_reg_groups(id),
CONSTRAINT fk_rails_3824183ebe FOREIGN KEY (room_id) REFERENCES public.rooms(id),
CONSTRAINT fk_rails_60da5df21a FOREIGN KEY (supplementary_kit_id) REFERENCES public.supplementary_kits(id),
CONSTRAINT fk_rails_ab5773a75f FOREIGN KEY (service_id) REFERENCES public.services(id),
CONSTRAINT fk_rails_ae5fa0b57f FOREIGN KEY (device_model_id) REFERENCES public.device_models(id)
);
CREATE INDEX index_devices_on_device_model_id ON public.devices USING btree (device_model_id);
CREATE INDEX index_devices_on_device_reg_group_id ON public.devices USING btree (device_reg_group_id);
CREATE UNIQUE INDEX index_devices_on_inventory_id ON public.devices USING btree (inventory_id);
CREATE INDEX index_devices_on_room_id ON public.devices USING btree (room_id);
CREATE INDEX index_devices_on_service_id ON public.devices USING btree (service_id);
CREATE INDEX index_devices_on_supplementary_kit_id ON public.devices USING btree (supplementary_kit_id);
CREATE UNIQUE INDEX index_devices_on_tabel_id ON public.devices USING btree (tabel_id);
-- Permissions
ALTER TABLE public.devices OWNER TO postgres;
GRANT ALL ON TABLE public.devices TO postgres;
-- public.inspections definition
-- Drop table
-- DROP TABLE public.inspections;
CREATE TABLE public.inspections (
id bigserial NOT NULL,
device_id int8 NOT NULL,
type_target varchar NOT NULL,
state varchar NOT NULL,
conclusion_date timestamp(6) NULL,
conclusion varchar NULL,
description text NULL,
creator_id int8 NOT NULL,
performer_id int8 NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT inspections_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_183fe12b49 FOREIGN KEY (device_id) REFERENCES public.devices(id),
CONSTRAINT fk_rails_5d7a8ba713 FOREIGN KEY (creator_id) REFERENCES public.users(id),
CONSTRAINT fk_rails_8573ab9766 FOREIGN KEY (performer_id) REFERENCES public.users(id)
);
CREATE INDEX index_inspections_on_creator_id ON public.inspections USING btree (creator_id);
CREATE INDEX index_inspections_on_device_id ON public.inspections USING btree (device_id);
CREATE INDEX index_inspections_on_performer_id ON public.inspections USING btree (performer_id);
-- Permissions
ALTER TABLE public.inspections OWNER TO postgres;
GRANT ALL ON TABLE public.inspections TO postgres;
-- public.posts definition
-- Drop table
-- DROP TABLE public.posts;
CREATE TABLE public.posts (
id bigserial NOT NULL,
user_id int8 NOT NULL,
title varchar NULL,
body text NULL,
category varchar NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT posts_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_5b5ddfd518 FOREIGN KEY (user_id) REFERENCES public.users(id)
);
CREATE INDEX index_posts_on_user_id ON public.posts USING btree (user_id);
-- Permissions
ALTER TABLE public.posts OWNER TO postgres;
GRANT ALL ON TABLE public.posts TO postgres;
-- public.servers definition
-- Drop table
-- DROP TABLE public.servers;
CREATE TABLE public.servers (
id bigserial NOT NULL,
"name" varchar NULL,
ip_adress varchar NULL,
inventory_id int4 NULL,
service_id int8 NOT NULL,
room_id int8 NOT NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT servers_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_40364c1f8f FOREIGN KEY (room_id) REFERENCES public.rooms(id),
CONSTRAINT fk_rails_66cce08090 FOREIGN KEY (service_id) REFERENCES public.services(id)
);
CREATE INDEX index_servers_on_room_id ON public.servers USING btree (room_id);
CREATE INDEX index_servers_on_service_id ON public.servers USING btree (service_id);
-- Permissions
ALTER TABLE public.servers OWNER TO postgres;
GRANT ALL ON TABLE public.servers TO postgres;
-- public.channels definition
-- Drop table
-- DROP TABLE public.channels;
CREATE TABLE public.channels (
id bigserial NOT NULL,
"name" varchar NULL,
channel_id int4 NULL,
device_id int8 NOT NULL,
room_id int8 NOT NULL,
server_id int8 NOT NULL,
service_id int8 NOT NULL,
location_description text NULL,
self_background float8 NULL DEFAULT 0.0,
pre_emergency_limit float8 NULL DEFAULT 1.0,
emergency_limit float8 NULL DEFAULT 2.0,
consumptiom float8 NULL DEFAULT 1.0,
conversion_coefficient float8 NULL DEFAULT 0.0,
event_system_value float8 NULL DEFAULT 0.0,
event_not_system_value float8 NULL DEFAULT 0.0,
event_impulse_value float8 NULL DEFAULT 0.0,
event_datetime timestamp(6) NULL,
event_count int4 NULL DEFAULT 0,
event_error_count int4 NULL DEFAULT 0,
is_special_control bool NULL DEFAULT false,
is_online bool NULL,
state varchar NULL DEFAULT 'normal'::character varying,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT channels_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_3484cf4de2 FOREIGN KEY (device_id) REFERENCES public.devices(id),
CONSTRAINT fk_rails_6a40f1b796 FOREIGN KEY (service_id) REFERENCES public.services(id),
CONSTRAINT fk_rails_75998992af FOREIGN KEY (server_id) REFERENCES public.servers(id),
CONSTRAINT fk_rails_d2d6bb4242 FOREIGN KEY (room_id) REFERENCES public.rooms(id)
);
CREATE INDEX index_channels_on_device_id ON public.channels USING btree (device_id);
CREATE INDEX index_channels_on_room_id ON public.channels USING btree (room_id);
CREATE INDEX index_channels_on_server_id ON public.channels USING btree (server_id);
CREATE INDEX index_channels_on_service_id ON public.channels USING btree (service_id);
-- Permissions
ALTER TABLE public.channels OWNER TO postgres;
GRANT ALL ON TABLE public.channels TO postgres;
-- public.histories definition
-- Drop table
-- DROP TABLE public.histories;
CREATE TABLE public.histories (
id bigserial NOT NULL,
channel_id int8 NOT NULL,
event_impulse_value float8 NULL,
event_system_value float8 NULL,
event_not_system_value float8 NULL,
event_datetime timestamp(6) NULL,
created_at timestamp(6) NOT NULL,
updated_at timestamp(6) NOT NULL,
CONSTRAINT histories_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_7f43dbe0e4 FOREIGN KEY (channel_id) REFERENCES public.channels(id)
);
CREATE INDEX index_histories_on_channel_id ON public.histories USING btree (channel_id);
-- Permissions
ALTER TABLE public.histories OWNER TO postgres;
GRANT ALL ON TABLE public.histories TO postgres;
-- Permissions
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
-
Клонируем проект и собираем его
git clone git@github.com:digital-armstrong/Armstrong.Server.git \ && cd Armstrong.Server \ && dotnet build
-
Подключаем в USB-порт конвертер RS485 <-> USB и определяем имя порта:
ls /dev | grep -i ttyUSB
➜ ttyUSB0
Подразумевается, что вы знаете, какой сервер будет опрашиваться через этот конвертер, для простоты примем, что через конвертер на порту
ttyUSB0
будет опрашиваться сервер с ID 1. -
Добавляем сервер в настройки:
В файл
appsettings.json
в секцию ServerProps добавляем настройку как элемент массива:├── GeneralSettings └── ServerProps
"ServerProps": [ { "ServerId": 1, "DeadPollingTime": 100, "PollingTimeout": 10000, "MinimalPollingTimeout": 1000, "ComPortName": "/dev/ttyUSB0", "ComPortBaudRate": 9600 } ]
Если вам требуется опрашивать несколько серверов, то повторяете пункт 2 для выяснения имени порта и добавляете следующий элемент массива:
"ServerProps": [ { "ServerId": 1, "DeadPollingTime": 100, "PollingTimeout": 10000, "MinimalPollingTimeout": 1000, "ComPortName": "/dev/ttyUSB0", "ComPortBaudRate": 9600 }, { "ServerId": 2, "DeadPollingTime": 100, "PollingTimeout": 10000, "MinimalPollingTimeout": 1000, "ComPortName": "/dev/ttyUSB1", "ComPortBaudRate": 9600 } ]
-
Конфигурируем подключение к базе данных:
"SqlConnectionSettings": { "Host": "<databases_ip or domain>", "Username": "<database user>", "Password": "<users pswd>", "Database": "<databases name>" }
-
Запускаем проект:
dotnet run
-
Повторяем все манипуляции до пункта 4 из предыдущего раздела и собираем проект:
dotnet build
-
Создаем файл-сервис для systemd:
cd /etc/system/system \ && touch arms.service
[Unit] Description=ARMStrong server After=multi-user.target [Service] Type=simple Restart=always ExecStart=/usr/bin/dotnet /root/Armstrong.Server [Install] WantedBy=multi-user.target
Обратите внимание на
ExecStart
, путь до dotnet может быть как/usr/bin/dotnet
, если вы добавляли ссылку, если нет, то путь будет/root/.dotnet/dotnet
. -
Запускаем сервис и добавляем его в автозагрузку:
sudo systemctl enable arms.service
sudo systemctl start arms.service
-
Собираем контейнер:
docker build -t armstrongserver .
-
Конфигурируем docker-compose:
В файл
docker-compose.yml
в секциюserver/devices
добавляем адреса наших портов, например так:services: server: ... devices: - /dev/ttyUSB0:/dev/ttyUSB0 - /dev/ttyUSB1:/dev/ttyUSB1
И собираем docker-compose:
docker-compose build
Такой подход позволяет нам избавиться от ошибки доступа к портам и не использовать root-доступ из контейнера.