Актуализировал скрипты ручного создания баз данных

This commit is contained in:
YPermitin
2020-08-12 21:52:14 +05:00
parent 27fcd1a6f9
commit cfc12fd2be
3 changed files with 692 additions and 363 deletions
@@ -1,156 +1,268 @@
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
create table if not exists "Applications"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_Applications"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Applications" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Applications" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Applications_InformationSystemId_Id"
on "Applications" ("InformationSystemId", "Id");
create index if not exists "IX_Applications_InformationSystemId_Name"
on "Applications" ("InformationSystemId", "Name");
create table if not exists "Computers"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_Computers"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Computers" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Computers" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Computers_InformationSystemId_Id"
on "Computers" ("InformationSystemId", "Id");
create index if not exists "IX_Computers_InformationSystemId_Name"
on "Computers" ("InformationSystemId", "Name");
create table if not exists "Events"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
"Presentation" varchar(500),
constraint "PK_Events"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Events" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Events" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Events_InformationSystemId_Id"
on "Events" ("InformationSystemId", "Id");
create index if not exists "IX_Events_InformationSystemId_Name"
on "Events" ("InformationSystemId", "Name");
create table if not exists "InformationSystems"
(
"Id" bigint generated by default as identity
constraint "PK_InformationSystems"
primary key,
"Name" varchar(250),
"Description" varchar(500)
);
CREATE TABLE "InformationSystems" (
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
"Description" character varying(500) NULL,
CONSTRAINT "PK_InformationSystems" PRIMARY KEY ("Id")
create unique index if not exists "IX_InformationSystems_Id"
on "InformationSystems" ("Id");
create table if not exists "LogFiles"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"FileName" text,
"CreateDate" timestamp not null,
"ModificationDate" timestamp not null,
"LastEventNumber" bigint not null,
"LastCurrentFileReferences" text,
"LastCurrentFileData" text,
"LastStreamPosition" bigint,
constraint "PK_LogFiles"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "LogFiles" (
"InformationSystemId" bigint NOT NULL,
"FileName" text NOT NULL,
"CreateDate" timestamp without time zone NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"ModificationDate" timestamp without time zone NOT NULL,
"LastEventNumber" bigint NOT NULL,
"LastCurrentFileReferences" text NULL,
"LastCurrentFileData" text NULL,
"LastStreamPosition" bigint NULL,
CONSTRAINT "PK_LogFiles" PRIMARY KEY ("InformationSystemId", "FileName", "CreateDate", "Id")
create unique index if not exists "IX_LogFiles_InformationSystemId_FileName_CreateDate_Id"
on "LogFiles" ("InformationSystemId", "FileName", "CreateDate", "Id");
create table if not exists "Metadata"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
"Uuid" uuid not null,
constraint "PK_Metadata"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Metadata" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Uuid" uuid NOT NULL,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Metadata" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Metadata_InformationSystemId_Id"
on "Metadata" ("InformationSystemId", "Id");
create index if not exists "IX_Metadata_InformationSystemId_Name_Uuid"
on "Metadata" ("InformationSystemId", "Name", "Uuid");
create table if not exists "PrimaryPorts"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_PrimaryPorts"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "PrimaryPorts" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_PrimaryPorts" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_PrimaryPorts_InformationSystemId_Id"
on "PrimaryPorts" ("InformationSystemId", "Id");
create index if not exists "IX_PrimaryPorts_InformationSystemId_Name"
on "PrimaryPorts" ("InformationSystemId", "Name");
create table if not exists "RowsData"
(
"InformationSystemId" bigint not null,
"Id" bigint not null,
"Period" timestamp with time zone not null,
"SeverityId" bigint,
"ConnectId" bigint,
"Session" bigint,
"TransactionStatusId" bigint,
"TransactionDate" timestamp,
"TransactionId" bigint,
"UserId" bigint,
"ComputerId" bigint,
"ApplicationId" bigint,
"EventId" bigint,
"Comment" text,
"MetadataId" bigint,
"Data" text,
"DataUUID" text,
"DataPresentation" text,
"WorkServerId" bigint,
"PrimaryPortId" bigint,
"SecondaryPortId" bigint,
constraint "PK_RowsData"
primary key ("InformationSystemId", "Period", "Id")
);
CREATE TABLE "RowsData" (
"InformationSystemId" bigint NOT NULL,
"Period" timestamp with time zone NOT NULL,
"Id" bigint NOT NULL,
"SeverityId" bigint NULL,
"ConnectId" bigint NULL,
"Session" bigint NULL,
"TransactionStatusId" bigint NULL,
"TransactionDate" timestamp without time zone NULL,
"TransactionId" bigint NULL,
"UserId" bigint NULL,
"ComputerId" bigint NULL,
"ApplicationId" bigint NULL,
"EventId" bigint NULL,
"Comment" text NULL,
"MetadataId" bigint NULL,
"Data" text NULL,
"DataUUID" text NULL,
"DataPresentation" text NULL,
"WorkServerId" bigint NULL,
"PrimaryPortId" bigint NULL,
"SecondaryPortId" bigint NULL,
CONSTRAINT "PK_RowsData" PRIMARY KEY ("InformationSystemId", "Period", "Id")
create index if not exists "IX_RowsData_InformationSystemId_DataUUID"
on "RowsData" ("InformationSystemId", "DataUUID");
create unique index if not exists "IX_RowsData_InformationSystemId_Period_Id"
on "RowsData" ("InformationSystemId", "Period", "Id");
create index if not exists "IX_RowsData_InformationSystemId_UserId_Period"
on "RowsData" ("InformationSystemId", "UserId", "Period");
create table if not exists "SecondaryPorts"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_SecondaryPorts"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "SecondaryPorts" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_SecondaryPorts" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_SecondaryPorts_InformationSystemId_Id"
on "SecondaryPorts" ("InformationSystemId", "Id");
create index if not exists "IX_SecondaryPorts_InformationSystemId_Name"
on "SecondaryPorts" ("InformationSystemId", "Name");
create table if not exists "Severities"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_Severities"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Severities" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Severities" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Severities_InformationSystemId_Id"
on "Severities" ("InformationSystemId", "Id");
create index if not exists "IX_Severities_InformationSystemId_Name"
on "Severities" ("InformationSystemId", "Name");
create table if not exists "TransactionStatuses"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_TransactionStatuses"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "TransactionStatuses" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_TransactionStatuses" PRIMARY KEY ("InformationSystemId", "Id")
create table if not exists "Users"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
"Uuid" uuid not null,
constraint "PK_Users"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "Users" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Uuid" uuid NOT NULL,
"Name" character varying(250) NULL,
CONSTRAINT "PK_Users" PRIMARY KEY ("InformationSystemId", "Id")
create unique index if not exists "IX_Users_InformationSystemId_Id"
on "Users" ("InformationSystemId", "Id");
create index if not exists "IX_Users_InformationSystemId_Name_Uuid"
on "Users" ("InformationSystemId", "Name", "Uuid");
create table if not exists "WorkServers"
(
"InformationSystemId" bigint not null,
"Id" bigint generated by default as identity,
"Name" varchar(500),
constraint "PK_WorkServers"
primary key ("InformationSystemId", "Id")
);
CREATE TABLE "WorkServers" (
"InformationSystemId" bigint NOT NULL,
"Id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" character varying(250) NULL,
CONSTRAINT "PK_WorkServers" PRIMARY KEY ("InformationSystemId", "Id")
);
create unique index if not exists "IX_WorkServers_InformationSystemId_Id"
on "WorkServers" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_Applications_InformationSystemId_Id" ON "Applications" ("InformationSystemId", "Id");
create index if not exists "IX_WorkServers_InformationSystemId_Name"
on "WorkServers" ("InformationSystemId", "Name");
CREATE UNIQUE INDEX "IX_Computers_InformationSystemId_Id" ON "Computers" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_Events_InformationSystemId_Id" ON "Events" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_InformationSystems_Id" ON "InformationSystems" ("Id");
CREATE UNIQUE INDEX "IX_LogFiles_InformationSystemId_FileName_CreateDate_Id" ON "LogFiles" ("InformationSystemId", "FileName", "CreateDate", "Id");
CREATE UNIQUE INDEX "IX_Metadata_InformationSystemId_Id" ON "Metadata" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_PrimaryPorts_InformationSystemId_Id" ON "PrimaryPorts" ("InformationSystemId", "Id");
CREATE INDEX "IX_RowsData_InformationSystemId_DataUUID" ON "RowsData" ("InformationSystemId", "DataUUID");
CREATE UNIQUE INDEX "IX_RowsData_InformationSystemId_Period_Id" ON "RowsData" ("InformationSystemId", "Period", "Id");
CREATE INDEX "IX_RowsData_InformationSystemId_UserId_Period" ON "RowsData" ("InformationSystemId", "UserId", "Period");
CREATE UNIQUE INDEX "IX_SecondaryPorts_InformationSystemId_Id" ON "SecondaryPorts" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_Severities_InformationSystemId_Id" ON "Severities" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_TransactionStatuses_InformationSystemId_Id" ON "TransactionStatuses" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_Users_InformationSystemId_Id" ON "Users" ("InformationSystemId", "Id");
CREATE UNIQUE INDEX "IX_WorkServers_InformationSystemId_Id" ON "WorkServers" ("InformationSystemId", "Id");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20200509202647_Initialization', '3.1.3');
create or replace view vw_eventlog("InformationSystemId", "InformationSystemName", "Period", "RowId", "SeverityId", "SeverityName", "Connection", "Session", "TransactionStatusId", "TransactionDate", "TransactionId", "UserId", "UserName", "UserUUID", "ComputerId", "ComputerName", "Data", "DataUUID", "DataPresentation", "Comment", "ApplicationId", "ApplicationName", "EventId", "EventName", "MetadataId", "MetadataName", "MetadataUUID", "WorkServerId", "WorkServerName", "PrimaryPortId", "PrimaryPortName", "SecondaryPortId", "SecondaryPortName") as
SELECT "RD"."InformationSystemId",
"IS"."Name" AS "InformationSystemName",
"RD"."Period",
"RD"."Id" AS "RowId",
"RD"."SeverityId",
"SV"."Name" AS "SeverityName",
"RD"."ConnectId" AS "Connection",
"RD"."Session",
"RD"."TransactionStatusId",
"RD"."TransactionDate",
"RD"."TransactionId",
"RD"."UserId",
"USR"."Name" AS "UserName",
"USR"."Uuid" AS "UserUUID",
"RD"."ComputerId",
"CMP"."Name" AS "ComputerName",
"RD"."Data",
"RD"."DataUUID",
"RD"."DataPresentation",
"RD"."Comment",
"RD"."ApplicationId",
"APPS"."Name" AS "ApplicationName",
"RD"."EventId",
"EVNT"."Name" AS "EventName",
"RD"."MetadataId",
"META"."Name" AS "MetadataName",
"META"."Uuid" AS "MetadataUUID",
"RD"."WorkServerId",
"WSRV"."Name" AS "WorkServerName",
"RD"."PrimaryPortId",
"PPRT"."Name" AS "PrimaryPortName",
"RD"."SecondaryPortId",
"SPRT"."Name" AS "SecondaryPortName"
FROM "RowsData" "RD"
LEFT JOIN "InformationSystems" "IS" ON "RD"."InformationSystemId" = "IS"."Id"
LEFT JOIN "Severities" "SV"
ON "RD"."InformationSystemId" = "SV"."InformationSystemId" AND "RD"."SeverityId" = "SV"."Id"
LEFT JOIN "Users" "USR"
ON "RD"."InformationSystemId" = "USR"."InformationSystemId" AND "RD"."UserId" = "USR"."Id"
LEFT JOIN "Computers" "CMP"
ON "RD"."InformationSystemId" = "CMP"."InformationSystemId" AND "RD"."ComputerId" = "CMP"."Id"
LEFT JOIN "Applications" "APPS"
ON "RD"."InformationSystemId" = "APPS"."InformationSystemId" AND "RD"."ApplicationId" = "APPS"."Id"
LEFT JOIN "Events" "EVNT"
ON "RD"."InformationSystemId" = "EVNT"."InformationSystemId" AND "RD"."EventId" = "EVNT"."Id"
LEFT JOIN "Metadata" "META"
ON "RD"."InformationSystemId" = "META"."InformationSystemId" AND "RD"."MetadataId" = "META"."Id"
LEFT JOIN "WorkServers" "WSRV"
ON "RD"."InformationSystemId" = "WSRV"."InformationSystemId" AND "RD"."WorkServerId" = "WSRV"."Id"
LEFT JOIN "PrimaryPorts" "PPRT"
ON "RD"."InformationSystemId" = "PPRT"."InformationSystemId" AND "RD"."PrimaryPortId" = "PPRT"."Id"
LEFT JOIN "SecondaryPorts" "SPRT" ON "RD"."InformationSystemId" = "SPRT"."InformationSystemId" AND
"RD"."SecondaryPortId" = "SPRT"."Id";