Содержание

Этап создания структуры базы данных LSS проекта

lss

Введение

На этом этапе мы создадим необходимые таблицы в базе данных SQL сервера, опишем эти таблицы в LSS проекте и сформируем по описателям контроллеры источников данных DataSource.

Развертывание этапа на площадке

Описание

Создание структуры таблиц в базе SQL сервера

Структура базы данных LSS проекта лежит в файле sql/tables.sql в виде SQL скрипта:

-- роль доступа
create table "role" (
	"id" bigserial primary key,
	"code" varchar(64) not null default '',
	"name" varchar(255) not null default ''
);
create unique index "uidx_role_code" on "role" ("code") where "id">0;
create unique index "uidx_role_name" on "role" ("name") where "id">0;

-- пользователь системы
create table "user" (
	"id" bigserial primary key,
	"login" varchar(64) not null default '',
	"password" varchar(255) not null default '',
	"fio" varchar(255) not null default '',
	"roleid" bigint references "role" deferrable initially deferred
);
create index "idx_user_roleid" on "user" ("roleid");
create unique index "uidx_user_login" on "user" ("login") where "id">0;

-- цех
create table "department" (
	"id" bigserial primary key,
	"name" varchar(255) not null default ''
);
create unique index "uidx_department_name" on "department" ("name") where "id">0;

-- участок
create table "sector" (
	"id" bigserial primary key,
	"departmentid" bigint references "department" on delete cascade deferrable initially deferred,
	"name" varchar(255) not null default ''
);
create index "idx_sector_departmentid" on "sector" ("departmentid");
create unique index "uidx_sector_unique" on "sector" ("departmentid", "name") where "id">0;

-- тип оборудования
create table "machinetype" (
	"id" bigserial primary key,
	"name" varchar(255) not null default ''
);
create unique index "uidx_machinetype_name" on "machinetype" ("name") where "id">0;

-- состояние оборудования
create table "machinestatus" (
	"id" bigserial primary key,
	"name" varchar(255) not null default ''
);
create unique index "uidx_machinestatus_name" on "machinestatus" ("name") where "id">0;

-- вид ремонта
create table "repair" (
	"id" bigserial primary key,
	"name" varchar(255) not null default '',
	"npp" int not null default 0
);
create unique index "uidx_repair_name" on "repair" ("name") where "id">0;

-- паспорт оборудования
create table "machine" (
	"id" bigserial primary key,
	"dfrom" date,
	"invnum" varchar(64) not null default '',
	"machinetypeid" bigint references "machinetype" deferrable initially deferred,
	"model" varchar(64) not null default '',
	"departmentid" bigint references "department" deferrable initially deferred,
	"sectorid" bigint references "sector" deferrable initially deferred,
	"dstatus" date,
	"machinestatusid" bigint references "machinestatus" deferrable initially deferred
);
create index "idx_machine_machinetypeid" on "machine" ("machinetypeid");
create index "idx_machine_departmentid" on "machine" ("departmentid");
create index "idx_machine_sectorid" on "machine" ("sectorid");
create index "idx_machine_machinestatusid" on "machine" ("machinestatusid");
create unique index "uidx_machine_invnum" on "machine" ("invnum") where "id">0;

-- ремонт оборудования
create table "machinerepair" (
	"id" bigserial primary key,
	"machineid" bigint references "machine" on delete cascade deferrable initially deferred,
	"repairid" bigint references "repair" deferrable initially deferred,
	"dplan" date,
	"dfact" date
);
create index "idx_machinerepair_machineid" on "machinerepair" ("machineid");
create index "idx_machinerepair_repairid" on "machinerepair" ("repairid");

-- нормы ремонтов
create table "repairnorm" (
	"id" bigserial primary key,
	"repairid" bigint references "repair" on delete cascade deferrable initially deferred,
	"machinetypeid" bigint references "machinetype" on delete cascade deferrable initially deferred,
	"period" bigint not null default 0
);
create index "idx_repairnorm_repairid" on "repairnorm" ("repairid");
create index "idx_repairnorm_machinetypeid" on "repairnorm" ("machinetypeid");
create unique index "uidx_repairnorm_unique" on "repairnorm" ("machinetypeid","repairid") where "id">0;

Этот скрипт написан вручную, содержит описание таблиц, полей, ссылочных целостностей, индексов. Его необходимо выполнить при развертывании этапа проекта на площадке.

Описание структуры базы данных LSS проекта

Поля и таблицы базы данных LSS проекта должны быть описаны. Для описания используется системная экранная форма Описание структуры базы данных, доступная из главного меню системы как Разработка/Структура базы.

Описатели хранятся в системных таблицах: systablecategory, systable, sysfield, sysfieldparams.

Эти описатели содержат информацию, необходимую для нормальной работы источников данных и экранных форм, например:

Описатели были заполнены посредством этой экранной формы, а затем выгружены в виде исполняемого SQL скрипта, посредством вызова пункта меню экранной формы: Экспорт/Экспорт системных справочников в виде SQL скрипта.

Таблицы в описателях делятся на 3 группы:

Экранная форма Описание структуры базы данных содержит механизмы экспорта и импорта содержимого таблиц базы данных, раздельно по этим 3 группам. Для экспорта/импорта используется папка export-import/backup. Экспорт возможен в формате XML или в виде исполняемого SQL скрипта.

Пункт меню Пересчет/Генератор классов DataSource автоматически формирует по описателям контроллеры источников данных DataSource. Размещаются они в папке php/datasources/autogen.

Демонстрационные примеры и ссылки

Демонстрационные примеры доступны в режиме «только чтение». Для входа используйте логин root, пароль 1.