
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='BUILD_FILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BUILD_FILE',NULL,'Primary SQL Server','Файл обновления',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Файл обновления',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE') WHERE [Schema]='FIES' and EntName='BUILD_FILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="BUILD_FILE" Description="Файл обновления" DNAttributes="{BuildVersion}" DisplayName="{0}" Inherits="VCLib.FILE"><Fields><Attribute Name="BuildVersion" Index="3220001" Type="string" Description="Версия" CharacterMaximumLength="9" Required="1"></Attribute><Attribute Name="BuildDescription" Index="3220002" Type="string" Description="Описание" CharacterMaximumLength="8000" Required="1"></Attribute><Attribute Name="RequiredVersion" Index="3220003" Type="string" Description="Требуемая версия" CharacterMaximumLength="9" Required="1"></Attribute><Attribute Name="BuildDate" Index="3220004" Type="date" Description="Дата" Required="1"></Attribute></Fields><DbMapping><Table name="T_BUILD_FILE"><Map Name="BuildVersion" Column="BuildVersion"></Map><Map Name="BuildDescription" Column="BuildDescription"></Map><Map Name="RequiredVersion" Column="RequiredVersion"></Map><Map Name="BuildDate" Column="BuildDate"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='BUILD_FILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='GEN_NUMBERS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GEN_NUMBERS',NULL,'Primary SQL Server','Генерация номеров',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Генерация номеров',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='GEN_NUMBERS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="GEN_NUMBERS" Description="Генерация номеров" PrimaryKey="GenNumbersID" UnrestrictedAccess="1"><Fields><Attribute Name="GenNumbersID" Index="5570001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="EntityID" Index="5570002" Type="int" Description="Сущность" Required="1"></Attribute><Attribute Name="NumberName" Index="5570003" Type="string" Description="Наименование группы номеров" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="NextNumber" Index="5570004" Type="bigint" Description="Следующий номер для генерации" Required="1"></Attribute></Fields><DbMapping><Table name="T_GEN_NUMBERS"><Map Name="GenNumbersID" Column="GenNumbersID"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="NumberName" Column="NumberName"></Map><Map Name="NextNumber" Column="NextNumber"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='GEN_NUMBERS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='LISTS_ENTITY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'LISTS_ENTITY',NULL,'Primary SQL Server','Списки',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Списки',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='LISTS_ENTITY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="LISTS_ENTITY" Description="Списки" PrimaryKey="ListsEntityID" DNAttributes="{ListName}" DisplayName="{0}"><Fields><Attribute Name="ListsEntityID" Index="5370001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ListName" Index="5370002" Type="string" Description="Наименование списка" CharacterMaximumLength="25" Required="1"></Attribute><Attribute Name="PreferedFilter" Index="5370005" Type="text" Description="Предустановленный фильтр"></Attribute><Attribute Name="HiddenFilter" Index="5370006" Type="text" Description="Скрытый фильтр"></Attribute><Attribute Name="Context" Index="5370007" Type="string" Description="Контекст"></Attribute><Attribute Name="MultiSelect" Index="5370008" Type="bool" Description="Множественное выделение" DefaultValue="false"></Attribute><Parent Name="Entities" Index="5370004" Type="VCLib.ENTITIES" Description="Сущности метаданных"></Parent><Child Name="ListsEntityUsersGroups" Index="5370003" Type="FIES.LISTS_ENTITY_USERS_GROUP" Description="Связь списков с группой пользователей" ChildAttribute="ListsEntity"></Child><Choice Name="ColorStyle" Index="5370009" Description="Стиль подсветки"><Item Name="COLOR_TYPE" Index="0"></Item><Item Name="COLOR_TYPE2" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_LISTS_ENTITY"><Map Name="ListsEntityID" Column="ListsEntityID"></Map><Map Name="ListName" Column="ListName"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="PreferedFilter" Column="PreferedFilter"></Map><Map Name="HiddenFilter" Column="HiddenFilter"></Map><Map Name="Context" Column="Context"></Map><Map Name="MultiSelect" Column="MultiSelect"></Map><Map Name="ColorStyle" Column="ColorStyle"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='LISTS_ENTITY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='LISTS_ENTITY_USERS_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'LISTS_ENTITY_USERS_GROUP',NULL,'Primary SQL Server','Связь списков с группой пользователей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь списков с группой пользователей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='LISTS_ENTITY_USERS_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="LISTS_ENTITY_USERS_GROUP" Description="Связь списков с группой пользователей" PrimaryKey="ListsEntityUsersGroupID"><Fields><Attribute Name="ListsEntityUsersGroupID" Index="5640001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="ListsEntity" Index="5640002" Type="FIES.LISTS_ENTITY" Description="Списки"></Parent><Parent Name="UsersGroup" Index="5640003" Type="VCLib.USERS_GROUP" Description="Группы пользователей"></Parent></Fields><DbMapping><Table name="T_LISTS_ENTITY_USERS_GROUP"><Map Name="ListsEntityUsersGroupID" Column="ListsEntityUsersGroupID"></Map><Map Name="ListsEntity" Column="ListsEntity"></Map><Map Name="UsersGroup" Column="UsersGroup"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='LISTS_ENTITY_USERS_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PARAMETER_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PARAMETER_GROUP',NULL,'Primary SQL Server','Группа параметров',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группа параметров',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PARAMETER_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PARAMETER_GROUP" Description="Группа параметров" PrimaryKey="ParameterGroupID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="ParameterGroupID" Index="5520001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5520002" Type="string" Description="Наменование" Required="1"></Attribute><Attribute Name="ParametrOrder" Index="5520004" Type="int" Description="Номер группы" Required="1"></Attribute><Attribute Name="GroupAlias" Index="5520005" Type="string" Description="Псевдоним" CharacterMaximumLength="20" Required="1"></Attribute><Child Name="PlanParameters" Index="5520003" Type="FIES.PLAN_PARAMETER" Description="Параметры" ChildAttribute="ParameterGroup"></Child></Fields><DbMapping><Table name="T_PARAMETER_GROUP"><Map Name="ParameterGroupID" Column="ParameterGroupID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ParametrOrder" Column="ParametrOrder"></Map><Map Name="GroupAlias" Column="GroupAlias"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PARAMETER_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PERIOD_SECTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PERIOD_SECTION',NULL,'Primary SQL Server','Раздел периодов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Раздел периодов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PERIOD_SECTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PERIOD_SECTION" Description="Раздел периодов" PrimaryKey="PeriodSectionID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="PeriodSectionID" Index="5600001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DateBegin" Index="5600002" Type="date" Description="Дата начала действия" Required="1"></Attribute><Attribute Name="DateEnd" Index="5600003" Type="date" Description="Дата окончания действия"></Attribute><Attribute Name="Name" Index="5600004" Type="string" Description="Название" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="Priority" Index="5600005" Type="int" Description="Приоритет" Required="1"></Attribute><Attribute Name="PeriodAlias" Index="5600006" Type="string" Description="Псевдоним" CharacterMaximumLength="250" Required="1"></Attribute><Parent Name="PeriodSection" Index="5600007" Type="FIES.PERIOD_SECTION" Description="Основной раздел периодов"></Parent><Child Name="PeriodSections" Index="5600008" Type="FIES.PERIOD_SECTION" Description="Дочерние разделы периодов" ChildAttribute="PeriodSection"></Child></Fields><DbMapping><Table name="T_PERIOD_SECTION"><Map Name="PeriodSectionID" Column="PeriodSectionID"></Map><Map Name="DateEnd" Column="DateEnd"></Map><Map Name="DateBegin" Column="DateBegin"></Map><Map Name="Name" Column="Name"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="PeriodAlias" Column="PeriodAlias"></Map><Map Name="PeriodSection" Column="PeriodSection"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PERIOD_SECTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_LIMIT_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_LIMIT_TYPE',NULL,'Primary SQL Server','Тип лимита',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Тип лимита',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_LIMIT_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_LIMIT_TYPE" Description="Тип лимита" PrimaryKey="PlanLimitTypeID"><Fields><Attribute Name="PlanLimitTypeID" Index="5510001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5510002" Type="string" Description="Наименование лимита" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="LimitColor" Index="5510003" Type="int" Description="Цвет обозначения" Required="1"></Attribute><Attribute Name="UserErrorText" Index="5510004" Type="string" Description="Сообщение о превышении" CharacterMaximumLength="512" Required="1"></Attribute><Attribute Name="DisplayOrder" Index="5510005" Type="int" Description="Порядок" Required="1"></Attribute><Attribute Name="TypeAlias" Index="5510006" Type="string" Description="Псевдоним" CharacterMaximumLength="20" Required="1"></Attribute></Fields><DbMapping><Table name="T_PLAN_LIMIT_TYPE"><Map Name="PlanLimitTypeID" Column="PlanLimitTypeID"></Map><Map Name="Name" Column="Name"></Map><Map Name="LimitColor" Column="LimitColor"></Map><Map Name="UserErrorText" Column="UserErrorText"></Map><Map Name="DisplayOrder" Column="DisplayOrder"></Map><Map Name="TypeAlias" Column="TypeAlias"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_LIMIT_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_PARAMETER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_PARAMETER',NULL,'Primary SQL Server','Параметр',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_PARAMETER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_PARAMETER" Description="Параметр" PrimaryKey="PlanParameterID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="PlanParameterID" Index="5420001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5420003" Type="string" Description="Наменование" Required="1"></Attribute><Attribute Name="IsMonthSplit" Index="5420004" Type="bool" Description="Разбивать по периодам" Required="1"></Attribute><Attribute Name="ParametrOrder" Index="5420005" Type="int" Description="Порядок" Required="1"></Attribute><Attribute Name="ParameterLexem" Index="5420008" Type="text" Description="Лексема"></Attribute><Attribute Name="DisplayGroupPath" Index="5420010" Type="string" Description="Группировка для пользователя" CharacterMaximumLength="1024"></Attribute><Attribute Name="ParameterAlias" Index="5420011" Type="string" Description="Псевдоним" CharacterMaximumLength="20" Required="1"></Attribute><Attribute Name="RoundSettings" Index="5420014" Type="text" Description="Настройка округления"></Attribute><Parent Name="ParameterGroup" Index="5420012" Type="FIES.PARAMETER_GROUP" Description="Группа параметров" Required="1"></Parent><Parent Name="PlanParameterLink" Index="5420013" Type="FIES.PLAN_PARAMETER" Description="Зависимость от параметра"></Parent><Child Name="PlanParametrSections" Index="5420009" Type="FIES.PLAN_PARAMETR_SECTION" Description="Доступные разделы планирования" ChildAttribute="PlanParameter"></Child><Choice Name="ParameterType" Index="5420007" Description="Тип параметра" Required="1"><Item Name="Простой" Index="0"></Item><Item Name="Вычислимый" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_PLAN_PARAMETER"><Map Name="PlanParameterID" Column="PayParametrID"></Map><Map Name="Name" Column="Name"></Map><Map Name="IsMonthSplit" Column="IsMonthSplit"></Map><Map Name="ParametrOrder" Column="ParametrOrder"></Map><Map Name="ParameterType" Column="DependType"></Map><Map Name="ParameterLexem" Column="ParameterLexem"></Map><Map Name="DisplayGroupPath" Column="DisplayGroupPath"></Map><Map Name="ParameterAlias" Column="ParameterAlias"></Map><Map Name="ParameterGroup" Column="ParameterGroup"></Map><Map Name="PlanParameterLink" Column="PlanParameterLink"></Map><Map Name="RoundSettings" Column="RoundSettings"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_PARAMETER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_PARAMETR_SECTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_PARAMETR_SECTION',NULL,'Primary SQL Server','Настройка доступности параметров по разделам',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка доступности параметров по разделам',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_PARAMETR_SECTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_PARAMETR_SECTION" Description="Настройка доступности параметров по разделам" PrimaryKey="PlanParametrSectionID" DNAttributes="{PlanParameter/Name};{PlanSection/Name}" DisplayName="{0} - {1}"><Fields><Attribute Name="PlanParametrSectionID" Index="5430001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="PlanSectionObjectID" Index="5430004" Type="string" Description="Ключ записи раздела планирования" CharacterMaximumLength="36"></Attribute><Attribute Name="PlanSectionObjectName" Index="5430005" Type="string" Description="Наименование записи раздела планирования" CharacterMaximumLength="255"></Attribute><Parent Name="PlanParameter" Index="5430002" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="PlanSection" Index="5430003" Type="FIES.PLAN_SECTION" Description="Раздел планирования" Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_PARAMETR_SECTION"><Map Name="PlanParametrSectionID" Column="PlanParametrSectionID"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="PlanSection" Column="PlanSection"></Map><Map Name="PlanSectionObjectID" Column="PlanSectionObjectID"></Map><Map Name="PlanSectionObjectName" Column="PlanSectionObjectName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_PARAMETR_SECTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_SECTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_SECTION',NULL,'Primary SQL Server','Раздел планирования',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Раздел планирования',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_SECTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_SECTION" Description="Раздел планирования" PrimaryKey="PlanSectionID" DNAttributes="{Entities/EntDesc}" DisplayName="{0}"><Fields><Attribute Name="PlanSectionID" Index="5380001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DateBegin" Index="5380003" Type="date" Description="Дата начала" Required="1"></Attribute><Attribute Name="DateEnd" Index="5380004" Type="date" Description="Дата окончания"></Attribute><Attribute Name="Name" Index="5380005" Type="string" Description="Название" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="SectionLevel" Index="5380006" Type="int" Description="Уровень раздела" Required="1"></Attribute><Attribute Name="SectionAlias" Index="5380008" Type="string" Description="Псевдоним" Required="1"></Attribute><Parent Name="Entities" Index="5380002" Type="VCLib.ENTITIES" Description="Сущность справочник" Required="1"></Parent><Child Name="PlanParametrSections" Index="5380007" Type="FIES.PLAN_PARAMETR_SECTION" Description="Доступные параметры" ChildAttribute="PlanSection"></Child></Fields><DbMapping><Table name="T_PLAN_SECTION"><Map Name="PlanSectionID" Column="PlanSectionID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="DateBegin" Column="DateBegin"></Map><Map Name="DateEnd" Column="DateEnd"></Map><Map Name="Name" Column="Name"></Map><Map Name="SectionLevel" Column="SectionLevel"></Map><Map Name="SectionAlias" Column="SectionAlias"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_SECTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PROGRAM_SETTINGS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PROGRAM_SETTINGS',NULL,'Primary SQL Server','Настройки программы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройки программы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PROGRAM_SETTINGS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PROGRAM_SETTINGS" Description="Настройки программы" PrimaryKey="ProgramSettingsID"><Fields><Attribute Name="ProgramSettingsID" Index="5680001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="IsMeeting" Index="5680002" Type="bool" Description="Утверждение комиссией" Required="1"></Attribute></Fields><DbMapping><Table name="T_PROGRAM_SETTINGS"><Map Name="ProgramSettingsID" Column="ProgramSettingsID"></Map><Map Name="IsMeeting" Column="IsMeeting"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PROGRAM_SETTINGS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SECTION_DEPEND_SETTINGS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SECTION_DEPEND_SETTINGS',NULL,'Primary SQL Server','Настройка связей между разделами',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка связей между разделами',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='SECTION_DEPEND_SETTINGS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SECTION_DEPEND_SETTINGS" Description="Настройка связей между разделами" PrimaryKey="SectionDependSettingsID"><Fields><Attribute Name="SectionDependSettingsID" Index="5490001" Type="guid" Description="Идентификатор"></Attribute></Fields><DbMapping><Table name="T_SECTION_DEPEND_SETTINGS"><Map Name="SectionDependSettingsID" Column="SectionDependSettingsID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SECTION_DEPEND_SETTINGS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SUBPROGRAMM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SUBPROGRAMM',NULL,'Primary SQL Server','Подпрограмма',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Подпрограмма',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='SUBPROGRAMM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SUBPROGRAMM" Description="Подпрограмма" PrimaryKey="SubprogrammID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="SubprogrammID" Index="5720001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5720002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Priority" Index="5720003" Type="int" Description="Приоритет" Required="1"></Attribute><Attribute Name="Condition" Index="5720004" Type="text" Description="Условие программы" Required="1"></Attribute></Fields><DbMapping><Table name="T_SUBPROGRAMM"><Map Name="SubprogrammID" Column="SubprogrammID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="Condition" Column="Condition"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SUBPROGRAMM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='USERS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USERS',NULL,'Primary SQL Server','Пользователи системы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_USERS'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Пользователи системы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_USERS') WHERE [Schema]='FIES' and EntName='USERS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="USERS" Description="Пользователи системы" version="2" DNAttributes="{UserName}" DisplayName="{0}" UnrestrictedAccess="0" Inherits="VCLib.BASE_USERS"><Fields><Parent Name="Mo" Index="310002" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6"></Parent><Parent Name="Smo" Index="310003" Type="FIES.SMO" Description="Страховая организация" CharacterMaximumLength="5"></Parent><Parent Name="TfomsBranch" Index="310004" Type="FIES.TFOMS_BRANCH" Description="Филиал ТФОМС"></Parent></Fields><DbMapping><Table name="T_USERS"><Map Name="Branch" Column="Branch"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="Smo" Column="Smo"></Map><Map Name="TfomsBranch" Column="TfomsBranch"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='USERS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='COMPANY_SETTINGS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'COMPANY_SETTINGS',NULL,'Primary SQL Server','Настройки ЛПУ',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройки ЛПУ',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='COMPANY_SETTINGS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="COMPANY_SETTINGS" Description="Настройки ЛПУ" PrimaryKey="CompanySettingsID" DisplayName="{0}"><Fields><Attribute Name="CompanySettingsID" Index="5090001" Type="guid" Description="Идентификатор"></Attribute></Fields><DbMapping><Table name="T_COMPANY_SETTINGS"><Map Name="CompanySettingsID" Column="CompanySettingsID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='COMPANY_SETTINGS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='WORKER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'WORKER',NULL,'Primary SQL Server','Сотрудник',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сотрудник',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='WORKER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="WORKER" Description="Сотрудник" PrimaryKey="WorkerID" DNAttributes="{FIO}" DisplayName="{0}"><Fields><Attribute Name="WorkerID" Index="5000001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="FirstName" Index="5000002" Type="string" Description="Имя" CharacterMaximumLength="32" Required="1"></Attribute><Attribute Name="LastName" Index="5000003" Type="string" Description="Фамилия" CharacterMaximumLength="32" Required="1"></Attribute><Attribute Name="FatherName" Index="5000004" Type="string" Description="Отчество" CharacterMaximumLength="32" Required="1"></Attribute><Attribute Name="FIO" Index="5000007" Type="string" Description="ФИО" CharacterMaximumLength="38"></Attribute><Child Name="WorkerHolidays" Index="5000014" Type="FIES.WORKER_HOLIDAY" Description="График отпусков, нерабочих дней" ChildAttribute="Worker"></Child></Fields><DbMapping><![CDATA[ъ
  ]]><Table name="T_WORKER"><Map Name="WorkerID" Column="WorkerID"></Map><Map Name="FirstName" Column="FirstName"></Map><Map Name="LastName" Column="LastName"></Map><Map Name="FatherName" Column="FatherName"></Map><Map Name="FIO" Column="FIO"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='WORKER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'WORKER_HOLIDAY',NULL,'Primary SQL Server','График отпусков, нерабочих дней',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='График отпусков, нерабочих дней',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="WORKER_HOLIDAY" Description="График отпусков, нерабочих дней" PrimaryKey="WorkerHolidayID" DNAttributes="{BeginDate};{EndDate}" DisplayName="{0} - {1}"><Fields><Attribute Name="WorkerHolidayID" Index="7780001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="BeginDate" Index="7780002" Type="date" Description="Дата начала" Required="1"></Attribute><Attribute Name="EndDate" Index="7780003" Type="date" Description="Дата окончания" Required="1"></Attribute><Parent Name="Worker" Index="7780006" Type="FIES.WORKER" Description="Сотрудник"></Parent><Child Name="WorkerHolidayTransfers" Index="7780007" Type="FIES.WORKER_HOLIDAY_TRANSFER" Description="График переноса нерабочих дней" ChildAttribute="WorkerHoliday"></Child></Fields><DbMapping><Table name="T_WORKER_HOLIDAY"><Map Name="WorkerHolidayID" Column="WorkerHolidayID"></Map><Map Name="BeginDate" Column="BeginDate"></Map><Map Name="EndDate" Column="EndDate"></Map><Map Name="Worker" Column="Worker"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY_TRANSFER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'WORKER_HOLIDAY_TRANSFER',NULL,'Primary SQL Server','График переноса нерабочих дней',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='График переноса нерабочих дней',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY_TRANSFER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="WORKER_HOLIDAY_TRANSFER" Description="График переноса нерабочих дней" PrimaryKey="WorkerHolidayTransferID" DNAttributes="{HolidayDate};{TransferDate}" DisplayName="{0} -&gt; {1}"><Fields><Attribute Name="WorkerHolidayTransferID" Index="7790001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="HolidayDate" Index="7790002" Type="date" Description="Нерабочий день" Required="1"></Attribute><Attribute Name="TransferDate" Index="7790003" Type="date" Description="Дата переноса"></Attribute><Parent Name="WorkerHoliday" Index="7790004" Type="FIES.WORKER_HOLIDAY" Description="График отпусков, нерабочих дней" Required="1"></Parent></Fields><DbMapping><Table name="T_WORKER_HOLIDAY_TRANSFER"><Map Name="WorkerHolidayTransferID" Column="WorkerHolidayTransferID"></Map><Map Name="HolidayDate" Column="HolidayDate"></Map><Map Name="TransferDate" Column="TransferDate"></Map><Map Name="WorkerHoliday" Column="WorkerHoliday"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='WORKER_HOLIDAY_TRANSFER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='COEFFICIENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'COEFFICIENT',NULL,'Primary SQL Server','Коэффициент',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Коэффициент',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='COEFFICIENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="COEFFICIENT" Description="Коэффициент" PrimaryKey="CoefficientID" DNAttributes="{CoefficientType/Name}" DisplayName="{0}"><Fields><Attribute Name="CoefficientID" Index="5240001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CoefficientValue" Index="5240004" Type="float" Description="Значение коэффициента" Required="1"></Attribute><Attribute Name="Priority" Index="5240005" Type="int" Description="Приоритет" Required="1"></Attribute><Attribute Name="CustomLexem" Index="5240006" Type="text" Description="Условие"></Attribute><Attribute Name="PercentValue" Index="5240007" Type="int" Description="Процент" Required="1"></Attribute><Attribute Name="RoundingAmount" Index="5240009" Type="int" Description="Количество знаков при округлении"></Attribute><Parent Name="Mo" Index="5240002" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6"></Parent><Parent Name="CoefficientType" Index="5240003" Type="FIES.COEFFICIENT_TYPE" Description="Тип коэффициента" Required="1"></Parent><Parent Name="CoefficientLexem" Index="5240008" Type="FIES.COEFFICIENT_LEXEM" Description="Условие применения коэффициента"></Parent></Fields><DbMapping><Table name="T_COEFFICIENT"><Map Name="CoefficientID" Column="CoefficientID"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="CoefficientType" Column="CoefficientType"></Map><Map Name="CoefficientValue" Column="CoefficientValue"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="CustomLexem" Column="CustomLexem"></Map><Map Name="PercentValue" Column="PercentValue"></Map><Map Name="CoefficientLexem" Column="CoefficientLexem"></Map><Map Name="RoundingAmount" Column="RoundingAmount"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='COEFFICIENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='COEFFICIENT_LEXEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'COEFFICIENT_LEXEM',NULL,'Primary SQL Server','Условие применения коэффициента',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Условие применения коэффициента',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='COEFFICIENT_LEXEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="COEFFICIENT_LEXEM" Description="Условие применения коэффициента" PrimaryKey="CoefficientLexemID" DNAttributes="{Code};{Name}" DisplayName="[{0}] {1}"><Fields><Attribute Name="CoefficientLexemID" Index="5290001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Condition" Index="5290002" Type="text" Description="Условие"></Attribute><Attribute Name="Name" Index="5290003" Type="string" Description="Наименование" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="Code" Index="5290004" Type="string" Description="Код" CharacterMaximumLength="10" Required="1"></Attribute></Fields><DbMapping><Table name="T_COEFFICIENT_LEXEM"><Map Name="CoefficientLexemID" Column="CoefficientLexemID"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="Name" Column="Name"></Map><Map Name="Code" Column="Code"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='COEFFICIENT_LEXEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='COEFFICIENT_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'COEFFICIENT_TYPE',NULL,'Primary SQL Server','Тип коэффициента',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Тип коэффициента',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='COEFFICIENT_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="COEFFICIENT_TYPE" Description="Тип коэффициента" PrimaryKey="CoefficientTypeID" DNAttributes="{Name};{Code}" DisplayName="[{0}] {1}"><Fields><Attribute Name="CoefficientTypeID" Index="5230001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5230002" Type="string" Description="Наименование коэффициента" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="Code" Index="5230003" Type="string" Description="Код" CharacterMaximumLength="10" Required="1"></Attribute></Fields><DbMapping><Table name="T_COEFFICIENT_TYPE"><Map Name="CoefficientTypeID" Column="CoefficientTypeID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Code" Column="Code"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='COEFFICIENT_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='DICTIONARY_BASE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_BASE',NULL,'Primary SQL Server','Базовый справочник',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Базовый справочник',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='DICTIONARY_BASE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="DICTIONARY_BASE" Description="Базовый справочник" PrimaryKey="DictionaryBaseID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="DictionaryBaseID" Index="5480001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Code" Index="5480002" Type="string" Description="Код" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="Name" Index="5480003" Type="string" Description="Наименование" CharacterMaximumLength="512" Required="1"></Attribute><Attribute Name="DateBegin" Index="5480004" Type="date" Description="Дата добавления" Required="1"></Attribute><Attribute Name="DateEnd" Index="5480005" Type="date" Description="Дата исключения"></Attribute><Attribute Name="EditDate" Index="5480006" Type="date" Description="Дата редактирования"></Attribute></Fields><DbMapping><Table name="T_DICTIONARY_BASE"><Map Name="DictionaryBaseID" Column="DictionaryBaseID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="DateBegin" Column="DateBegin"></Map><Map Name="DateEnd" Column="DateEnd"></Map><Map Name="EditDate" Column="EditDate"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='DICTIONARY_BASE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='F007_DEPARTMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'F007_DEPARTMENT',NULL,'Primary SQL Server','Классификатор ведомственной принадлежности медицинской организации',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор ведомственной принадлежности медицинской организации',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='F007_DEPARTMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="F007_DEPARTMENT" Description="Классификатор ведомственной принадлежности медицинской организации" PrimaryKey="IDVED" DNAttributes="{VEDNAME}" DisplayName="{0}"><Fields><Attribute Name="IDVED" Index="6960001" Type="int" Description="Код типа ведомства" Required="1"></Attribute><Attribute Name="VEDNAME" Index="6960002" Type="string" Description="Наименование ведомства" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="DATEBEG" Index="6960003" Type="date" Description="Дата начала действия записи" Required="1"></Attribute><Attribute Name="DATEEND" Index="6960004" Type="date" Description="Дата окончания действия записи"></Attribute></Fields><DbMapping><Table name="T_F007_DEPARTMENT"><Map Name="IDVED" Column="IDVED"></Map><Map Name="VEDNAME" Column="VEDNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='F007_DEPARTMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE',NULL,'Primary SQL Server','Сущность-связка между видом лицензии МО и мед. услугой',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сущность-связка между видом лицензии МО и мед. услугой',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE" Description="Сущность-связка между видом лицензии МО и мед. услугой" PrimaryKey="LinkMoLicenceTypeMedicalServiceID"><Fields><Attribute Name="LinkMoLicenceTypeMedicalServiceID" Index="5220001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="MoLicenceType" Index="5220002" Type="FIES.MO_LICENCE_TYPE" Description="Вид лицензии медицинской организации" Required="1"></Parent><Parent Name="MedicalService" Index="5220003" Type="FIES.MEDICAL_SERVICE" Description="Справочник услуг" Required="1"></Parent></Fields><DbMapping><Table name="T_LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE"><Map Name="LinkMoLicenceTypeMedicalServiceID" Column="LinkMoLicenceTypeMedicalServiceID"></Map><Map Name="MoLicenceType" Column="MoLicenceType"></Map><Map Name="MedicalService" Column="MedicalService"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MEDICAL_SERVICE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MEDICAL_SERVICE',NULL,'Primary SQL Server','Справочник услуг',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Справочник услуг',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MEDICAL_SERVICE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MEDICAL_SERVICE" Description="Справочник услуг" PrimaryKey="MedicalServiceID" DNAttributes="{Code};{Name}" DisplayName="[{0}] {1}"><Fields><Attribute Name="MedicalServiceID" Index="5050001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Code" Index="5050002" Type="string" Description="Код" CharacterMaximumLength="20" Required="1"></Attribute><Attribute Name="Name" Index="5050003" Type="string" Description="Наименование" CharacterMaximumLength="512" Required="1"></Attribute></Fields><DbMapping><Table name="T_MEDICAL_SERVICE"><Map Name="MedicalServiceID" Column="MedicalServiceID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MEDICAL_SERVICE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MO',NULL,'Primary SQL Server','Медицинская организация',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Медицинская организация',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MO" Description="Медицинская организация" PrimaryKey="MCOD" DNAttributes="{NAM_MFF}" DisplayName="{0}"><Fields><Attribute Name="TF_OKATO" Index="6940002" Type="string" Description="Код субъекта РФ по ОКАТО" CharacterMaximumLength="5" Required="1"></Attribute><Attribute Name="MCOD" Index="6940003" Type="string" Description="Код МО" CharacterMaximumLength="6" Required="1"></Attribute><Attribute Name="NAM_MOP" Index="6940004" Type="string" Description="Наименование МО полное" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="INN" Index="6940006" Type="string" Description="ИНН" CharacterMaximumLength="12" Required="1"></Attribute><Attribute Name="OGRN" Index="6940007" Type="string" Description="ОГРН" CharacterMaximumLength="15" Required="1"></Attribute><Attribute Name="KPP" Index="6940008" Type="string" Description="КПП" CharacterMaximumLength="9" Required="1"></Attribute><Attribute Name="INDEX_J" Index="6940009" Type="string" Description="Почтовый индекс юридического адреса МО" CharacterMaximumLength="6"></Attribute><Attribute Name="ADDR_J" Index="6940010" Type="string" Description="Юридический адрес МО" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="FAM_RUK" Index="6940014" Type="string" Description="Фамилия руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="IM_RUK" Index="6940015" Type="string" Description="Имя руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="OT_RUK" Index="6940016" Type="string" Description="Отчество руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="PHONE" Index="6940017" Type="string" Description="Телефон" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="FAX" Index="6940018" Type="string" Description="Факс" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="E_MAIL" Index="6940019" Type="string" Description="Адрес электронной почты" CharacterMaximumLength="50" Required="1"></Attribute><Attribute Name="MP" Index="6940023" Type="string" Description="Виды медицинской помощи" CharacterMaximumLength="15"></Attribute><Attribute Name="WWW" Index="6940024" Type="string" Description="Адрес сайта в сети интернет" CharacterMaximumLength="100"></Attribute><Attribute Name="D_BEGIN" Index="6940025" Type="date" Description="Дата включения в реестр МО"></Attribute><Attribute Name="D_END" Index="6940026" Type="date" Description="Дата исключения из реестра МО"></Attribute><Attribute Name="NAME_E" Index="6940027" Type="string" Description="Причина исключения МО из реестра МО" CharacterMaximumLength="10"></Attribute><Attribute Name="DUVED" Index="6940028" Type="date" Description="Дата уведомления об осуществлении деятельности в сфере ОМС"></Attribute><Attribute Name="D_EDIT" Index="6940029" Type="date" Description="Дата последнего редактирования"></Attribute><Attribute Name="IsActive" Index="6940033" Type="bool" Description="Активное" Required="1"></Attribute><Attribute Name="ShortFIODative" Index="6940038" Type="string" Description="ФИО в дательном падеже кратко" CharacterMaximumLength="50"></Attribute><Attribute Name="MO_NUMBER" Index="6940041" Type="string" Description="Номер МО" CharacterMaximumLength="40"></Attribute><Attribute Name="NAM_MOK" Index="6940042" Type="string" Description="Наименование МО краткое" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="IsFondHolder" Index="6940044" Type="bool" Description="Признак фондодержания"></Attribute><Attribute Name="IsUsingDigitalSignature" Index="6940046" Type="bool" Description="Признак использования ЭЦП"></Attribute><Attribute Name="NAM_MFF" Index="6970037" Type="string" Description="Наименование МО в свободной форме" CharacterMaximumLength="250" Required="1"></Attribute><Parent Name="OKOPF" Index="6940011" Type="FIES.O005_OKOPF" Description="ОКОПФ"></Parent><Parent Name="VEDPRI" Index="6940012" Type="FIES.F007_DEPARTMENT" Description="Ведомственная принадлежность МО"></Parent><Parent Name="MoType" Index="6940031" Type="FIES.MO_TYPE" Description="Тип МО"></Parent><Parent Name="Rajonrt" Index="6940037" Type="FIES.RAJONRT" Description="Район региона"></Parent><Child Name="MoLicences" Index="6940047" Type="FIES.MO_LICENCE" Description="Лицензия МО" ChildAttribute="Mo" SortingAttr="DateFrom"></Child><Child Name="Coefficients" Index="6940048" Type="FIES.COEFFICIENT" Description="Коэффициенты" ChildAttribute="Mo"></Child><Child Name="SmoCoefMonthValuesDefaults" Index="6940049" Type="FIES.SMO_COEF_MONTH_VALUES_DEFAULT" Description="Стандартные значения коэффициентов планов по СМО для МО" ChildAttribute="Mo" SortingAttr="Smo"></Child><Child Name="SmoCoefMonthValuesExceptions" Index="6970038" Type="FIES.SMO_COEF_MONTH_VALUES_EXCEPTION" Description="Исключения коэффициентов планов по СМО для МО" ChildAttribute="Mo"></Child><Choice Name="ORG" Index="6940013" Description="Признак подчиненности" Required="1"><Item Name="Головная организация" Index="1"></Item><Item Name="Филиал" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_MO"><Map Name="TF_OKATO" Column="TF_OKATO"></Map><Map Name="MCOD" Column="MCOD"></Map><Map Name="NAM_MOP" Column="NAM_MOP"></Map><Map Name="NAM_MOK" Column="NAM_MOK"></Map><Map Name="NAM_MFF" Column="NAM_MFF"></Map><Map Name="INN" Column="INN"></Map><Map Name="OGRN" Column="OGRN"></Map><Map Name="KPP" Column="KPP"></Map><Map Name="INDEX_J" Column="INDEX_J"></Map><Map Name="ADDR_J" Column="ADDR_J"></Map><Map Name="OKOPF" Column="OKOPF"></Map><Map Name="VEDPRI" Column="VEDPRI"></Map><Map Name="ORG" Column="ORG"></Map><Map Name="FAM_RUK" Column="FAM_RUK"></Map><Map Name="IM_RUK" Column="IM_RUK"></Map><Map Name="OT_RUK" Column="OT_RUK"></Map><Map Name="PHONE" Column="PHONE"></Map><Map Name="FAX" Column="FAX"></Map><Map Name="E_MAIL" Column="E_MAIL"></Map><Map Name="MP" Column="MP"></Map><Map Name="WWW" Column="WWW"></Map><Map Name="D_BEGIN" Column="D_BEGIN"></Map><Map Name="D_END" Column="D_END"></Map><Map Name="NAME_E" Column="NAME_E"></Map><Map Name="DUVED" Column="DUVED"></Map><Map Name="D_EDIT" Column="D_EDIT"></Map><Map Name="MoType" Column="MoType"></Map><Map Name="IsActive" Column="IsActive"></Map><Map Name="Rajonrt" Column="Rajonrt"></Map><Map Name="ShortFIODative" Column="ShortFIODative"></Map><Map Name="MO_NUMBER" Column="MO_NUMBER"></Map><Map Name="IsFondHolder" Column="IsFondHolder"></Map><Map Name="IsUsingDigitalSignature" Column="IsUsingDigitalSignature"></Map></Table></DbMapping><Customs><Custom Name="FilterUICondition"><![CDATA[<lx:Criterion type="=" xmlns:lx="lexem">
    <lx:Path OwnerQueryLevel="0">
      <lx:StepInt index="6940033" />
    </lx:Path>
    <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
  </lx:Criterion>]]></Custom></Customs></Entity>' WHERE [Schema]='FIES' and EntName='MO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MO_LICENCE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MO_LICENCE',NULL,'Primary SQL Server','Лицензия МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Лицензия МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MO_LICENCE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MO_LICENCE" Description="Лицензия МО" PrimaryKey="MoLicenceID"><Fields><Attribute Name="MoLicenceID" Index="5210001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DateFrom" Index="5210003" Type="date" Description="Дата действия с" Required="1"></Attribute><Attribute Name="DateTo" Index="5210004" Type="date" Description="Дата действия по"></Attribute><Parent Name="MoLicenceType" Index="5210002" Type="FIES.MO_LICENCE_TYPE" Description="Вид лицензии медицинской организации" Required="1"></Parent><Parent Name="Mo" Index="5210005" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent></Fields><DbMapping><Table name="T_MO_LICENCE"><Map Name="MoLicenceID" Column="MoLicenceID"></Map><Map Name="MoLicenceType" Column="MoLicenceType"></Map><Map Name="DateFrom" Column="DateFrom"></Map><Map Name="DateTo" Column="DateTo"></Map><Map Name="Mo" Column="Mo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MO_LICENCE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MO_LICENCE_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MO_LICENCE_TYPE',NULL,'Primary SQL Server','Вид лицензии медицинской организации',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Вид лицензии медицинской организации',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MO_LICENCE_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MO_LICENCE_TYPE" Description="Вид лицензии медицинской организации" PrimaryKey="MoLicenceTypeID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="MoLicenceTypeID" Index="5200001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5200003" Type="string" Description="Наименование лицензии" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="Code" Index="5200004" Type="string" Description="Код" CharacterMaximumLength="10" Required="1"></Attribute><Child Name="LinkMoLicenceTypeMedicalServices" Index="5200002" Type="FIES.LINK_MO_LICENCE_TYPE_MEDICAL_SERVICE" Description="Сущность-связка между видом лицензии МО и мед. услугой" ChildAttribute="MoLicenceType"></Child></Fields><DbMapping><Table name="T_MO_LICENCE_TYPE"><Map Name="MoLicenceTypeID" Column="MoLicenceTypeID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Code" Column="Code"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MO_LICENCE_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MO_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MO_TYPE',NULL,'Primary SQL Server','Тип МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Тип МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MO_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MO_TYPE" Description="Тип МО" PrimaryKey="MoTypeID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="MoTypeID" Index="5530001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Code" Index="5530002" Type="string" Description="Код" CharacterMaximumLength="5" Required="1"></Attribute><Attribute Name="Name" Index="5530003" Type="string" Description="Наименование" CharacterMaximumLength="255" Required="1"></Attribute></Fields><DbMapping><Table name="T_MO_TYPE"><Map Name="MoTypeID" Column="MoTypeID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MO_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='O001_OKSM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'O001_OKSM',NULL,'Primary SQL Server','Общероссийский классификатор стран мира',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Общероссийский классификатор стран мира',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='O001_OKSM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="O001_OKSM" Description="Общероссийский классификатор стран мира" PrimaryKey="KOD" DNAttributes="{NAME11}" DisplayName="{0}"><Fields><Attribute Name="KOD" Index="5250001" Type="string" Description="Цифровой Код" CharacterMaximumLength="3"></Attribute><Attribute Name="NAME11" Index="5250002" Type="string" Description="Краткое наименование" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="NAME12" Index="5250003" Type="string" Description="Официальное наименование" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="ALFA2" Index="5250004" Type="string" Description="Буквенный код альфа-2" CharacterMaximumLength="2" Required="1"></Attribute><Attribute Name="ALFA3" Index="5250005" Type="string" Description="Буквенный код альфа-3" CharacterMaximumLength="3" Required="1"></Attribute><Attribute Name="NOMDESCR" Index="5250006" Type="string" Description="Пояснение" CharacterMaximumLength="1000"></Attribute><Attribute Name="NOMAKT" Index="5250007" Type="string" Description="Номер последнего изменения" CharacterMaximumLength="3"></Attribute><Attribute Name="DATA_UPD" Index="5250008" Type="date" Description="Дата последнего изменения"></Attribute></Fields><DbMapping><Table name="T_O001_OKSM"><Map Name="KOD" Column="KOD"></Map><Map Name="NAME11" Column="NAME11"></Map><Map Name="NAME12" Column="NAME12"></Map><Map Name="ALFA2" Column="ALFA2"></Map><Map Name="ALFA3" Column="ALFA3"></Map><Map Name="NOMDESCR" Column="NOMDESCR"></Map><Map Name="NOMAKT" Column="NOMAKT"></Map><Map Name="DATA_UPD" Column="DATA_UPD"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='O001_OKSM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='O002_OKATO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'O002_OKATO',NULL,'Primary SQL Server','Общероссийский классификатор административно-территориального деления (ОКАТО)',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Общероссийский классификатор административно-территориального деления (ОКАТО)',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='O002_OKATO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="O002_OKATO" Description="Общероссийский классификатор административно-территориального деления (ОКАТО)" PrimaryKey="OkatoID"><Fields><Attribute Name="OkatoID" Index="5300001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CODE" Index="53000013" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11" Required="1"></Attribute><Attribute Name="TER" Index="5300002" Type="string" Description="Код территории" CharacterMaximumLength="2" Required="1"></Attribute><Attribute Name="KOD1" Index="5300003" Type="string" Description="Код района/города" CharacterMaximumLength="3" Required="1"></Attribute><Attribute Name="KOD2" Index="5300004" Type="string" Description="Код РП/сельсовета" CharacterMaximumLength="3" Required="1"></Attribute><Attribute Name="KOD3" Index="5300005" Type="string" Description="Код сельского населенного пункта" CharacterMaximumLength="3" Required="1"></Attribute><Attribute Name="RAZDEL" Index="5300006" Type="string" Description="Код раздела" CharacterMaximumLength="1"></Attribute><Attribute Name="NAME1" Index="5300007" Type="string" Description="Наименование " CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="CENTRUM" Index="5300008" Type="string" Description="Дополнительные данные" CharacterMaximumLength="80"></Attribute><Attribute Name="NOMDESCR" Index="5300009" Type="string" Description="Пояснение" CharacterMaximumLength="250"></Attribute><Attribute Name="NOMAKT" Index="5300010" Type="string" Description="Номер последнего изменения" CharacterMaximumLength="3"></Attribute><Attribute Name="STATUS" Index="5300011" Type="float" Description="Тип последнего изменения" NumericPrecision="25" NumericScale="5"></Attribute><Attribute Name="DATA_UPD" Index="5300012" Type="date" Description="Дата последнего изменения"></Attribute></Fields><DbMapping><Table name="T_O002_OKATO"><Map Name="OkatoID" Column="OkatoID"></Map><Map Name="TER" Column="TER"></Map><Map Name="KOD1" Column="KOD1"></Map><Map Name="KOD2" Column="KOD2"></Map><Map Name="KOD3" Column="KOD3"></Map><Map Name="RAZDEL" Column="RAZDEL"></Map><Map Name="NAME1" Column="NAME1"></Map><Map Name="CENTRUM" Column="CENTRUM"></Map><Map Name="NOMDESCR" Column="NOMDESCR"></Map><Map Name="NOMAKT" Column="NOMAKT"></Map><Map Name="STATUS" Column="STATUS"></Map><Map Name="DATA_UPD" Column="DATA_UPD"></Map><Map Name="CODE" Column="CODE"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='O002_OKATO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='O003_OKVED')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'O003_OKVED',NULL,'Primary SQL Server','Общероссийский классификатор видов экономической деятельности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Общероссийский классификатор видов экономической деятельности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='O003_OKVED'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="O003_OKVED" Description="Общероссийский классификатор видов экономической деятельности" PrimaryKey="KOD" DNAttributes="{NAME1}" DisplayName="{0}" IsTree="1"><Fields><Attribute Name="KOD" Index="5270001" Type="string" Description="Код" CharacterMaximumLength="8"></Attribute><Attribute Name="LeftIndex" Index="5270002" Type="int" Description="Левый индекс"></Attribute><Attribute Name="RightIndex" Index="5270003" Type="int" Description="Правый индекс"></Attribute><Attribute Name="TreeLevel" Index="5270004" Type="int" Description="Уровень дерева"></Attribute><Attribute Name="NAME1" Index="5270007" Type="string" Description="Наименование" CharacterMaximumLength="500" Required="1"></Attribute><Attribute Name="NOMDESCR" Index="5270008" Type="text" Description="Описание"></Attribute><Attribute Name="NOMAKT" Index="5270009" Type="string" Description="Номер последнего изменения" CharacterMaximumLength="3"></Attribute><Attribute Name="DATA_UPD" Index="5270011" Description="Дата последнего изменения"></Attribute><Parent Name="ParentID" Index="5270005" Type="FIES.O003_OKVED" Description="Родительская категория" CharacterMaximumLength="8"></Parent><Child Name="Children" Index="5270006" Type="FIES.O003_OKVED" Description="Дочерние категории" ChildAttribute="ParentID"></Child><Choice Name="STATUS" Index="5270010" Description="Тип последнего изменения"><Item Name="Анулировать" Index="1"></Item><Item Name="Изменить реквезит" Index="2"></Item><Item Name="Включить" Index="3"></Item><Item Name="Начальная загрузка" Index="0"></Item></Choice></Fields><DbMapping><Table name="T_O003_OKVED"><Map Name="KOD" Column="KOD"></Map><Map Name="LeftIndex" Column="LeftIndex"></Map><Map Name="RightIndex" Column="RightIndex"></Map><Map Name="TreeLevel" Column="TreeLevel"></Map><Map Name="ParentID" Column="ParentID"></Map><Map Name="NAME1" Column="NAME1"></Map><Map Name="NOMDESCR" Column="NOMDESCR"></Map><Map Name="NOMAKT" Column="NOMAKT"></Map><Map Name="STATUS" Column="STATUS"></Map><Map Name="DATA_UPD" Column="DATA_UPD"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='O003_OKVED'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='O004_OKFS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'O004_OKFS',NULL,'Primary SQL Server','Общероссийский классификатор форм собственности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Общероссийский классификатор форм собственности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='O004_OKFS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="O004_OKFS" Description="Общероссийский классификатор форм собственности" PrimaryKey="KOD" DNAttributes="{NAME1}" DisplayName="{0}"><Fields><Attribute Name="KOD" Index="5280001" Type="string" Description="Код" CharacterMaximumLength="2"></Attribute><Attribute Name="NAME1" Index="5280002" Type="string" Description="Наименование" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="ALG" Index="5280003" Type="string" Description="Алгоритм сбора" CharacterMaximumLength="52"></Attribute><Attribute Name="NOMAKT" Index="5280004" Type="string" Description="Номер последнего изменения" CharacterMaximumLength="3"></Attribute><Attribute Name="STATUS" Index="5280005" Type="int" Description="Тип последнего изменения"></Attribute><Attribute Name="DATA_UPD" Index="5280006" Type="date" Description="Дата последнего изменения"></Attribute></Fields><DbMapping><Table name="T_O004_OKFS"><Map Name="KOD" Column="KOD"></Map><Map Name="NAME1" Column="NAME1"></Map><Map Name="ALG" Column="ALG"></Map><Map Name="NOMAKT" Column="NOMAKT"></Map><Map Name="STATUS" Column="STATUS"></Map><Map Name="DATA_UPD" Column="DATA_UPD"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='O004_OKFS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='O005_OKOPF')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'O005_OKOPF',NULL,'Primary SQL Server','Общероссийский классификатор организационно-правовых форм',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Общероссийский классификатор организационно-правовых форм',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='O005_OKOPF'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="O005_OKOPF" Description="Общероссийский классификатор организационно-правовых форм" PrimaryKey="OkopfID" DNAttributes="{NAME1}" DisplayName="{0}"><Fields><Attribute Name="OkopfID" Index="6950001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="KOD" Index="6950002" Type="string" Description="Код" CharacterMaximumLength="5" Required="1"></Attribute><Attribute Name="NAME1" Index="6950003" Type="string" Description="Наименование" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="ALG" Index="6950004" Type="string" Description="Алгоритм сбора" CharacterMaximumLength="52"></Attribute><Attribute Name="NOMAKT" Index="6950005" Type="string" Description="Номер последнего изменения" CharacterMaximumLength="3"></Attribute><Attribute Name="STATUS" Index="6950006" Type="float" Description="Тип последнего изменения" NumericPrecision="20" NumericScale="5"></Attribute><Attribute Name="DATA_UPD" Index="6950007" Type="date" Description="Дата последнего изменения"></Attribute></Fields><DbMapping><Table name="T_O005_OKOPF"><Map Name="OkopfID" Column="O005OkopfID"></Map><Map Name="KOD" Column="KOD"></Map><Map Name="NAME1" Column="NAME1"></Map><Map Name="ALG" Column="ALG"></Map><Map Name="NOMAKT" Column="NOMAKT"></Map><Map Name="STATUS" Column="STATUS"></Map><Map Name="DATA_UPD" Column="DATA_UPD"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='O005_OKOPF'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PAY_CATEGORY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PAY_CATEGORY',NULL,'Primary SQL Server','Категория',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Категория',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PAY_CATEGORY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PAY_CATEGORY" Description="Категория" PrimaryKey="PayCategoryID" DNAttributes="{Code};{Name}" DisplayName="{0} - {1}" IsTree="1"><Fields><Attribute Name="PayCategoryID" Index="5020001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="LeftIndex" Index="5020002" Type="int" Description="Левый индекс"></Attribute><Attribute Name="RightIndex" Index="5020003" Type="int" Description="Правый индекс"></Attribute><Attribute Name="TreeLevel" Index="5020004" Type="int" Description="Уровень дерева"></Attribute><Attribute Name="Code" Index="5020007" Type="string" Description="Код" CharacterMaximumLength="20" Required="1"></Attribute><Attribute Name="Name" Index="5020008" Description="Наименование" Required="1"></Attribute><Parent Name="ParentID" Index="5020005" Type="FIES.PAY_CATEGORY" Description="Родительская категория"></Parent><Parent Name="PayParametrGroup" Index="5020010" Type="FIES.PAY_PARAMETR_GROUP" Description="Группа параметров" Required="1"></Parent><Child Name="Children" Index="5020006" Type="FIES.PAY_CATEGORY" Description="Дочерние категории" ChildAttribute="ParentID"></Child><Child Name="PayParametrServices" Index="5020009" Type="FIES.PAY_PARAMETR_SERVICE" Description="Параметры оплаты услуг" ChildAttribute="PayCategory"></Child></Fields><DbMapping><Table name="T_PAY_CATEGORY"><Map Name="PayCategoryID" Column="PayCategoryID"></Map><Map Name="LeftIndex" Column="LeftIndex"></Map><Map Name="RightIndex" Column="RightIndex"></Map><Map Name="TreeLevel" Column="TreeLevel"></Map><Map Name="ParentID" Column="ParentID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="PayParametrGroup" Column="PayParametrGroup"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PAY_CATEGORY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PAY_PARAMETR')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PAY_PARAMETR',NULL,'Primary SQL Server','Параметр',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PAY_PARAMETR'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PAY_PARAMETR" Description="Параметр" PrimaryKey="PayParametrID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="PayParametrID" Index="5040001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5040003" Type="string" Description="Наменование" Required="1"></Attribute><Attribute Name="IsMonthSplit" Index="5040004" Type="bool" Description="Разбивать по периодам" Required="1"></Attribute><Attribute Name="ParametrOrder" Index="5040005" Type="int" Description="Порядок" Required="1"></Attribute><Parent Name="PayParametrGroup" Index="5040002" Type="FIES.PAY_PARAMETR_GROUP" Description="Группа параметров" Required="1"></Parent><Parent Name="PayParametrMain" Index="5040006" Type="FIES.PAY_PARAMETR" Description="Основной параметр"></Parent><Choice Name="DependType" Index="5040007" Description="Тип зависимости" Required="1"><Item Name="Не зависимый" Index="0"></Item><Item Name="В том числе" Index="1"></Item><Item Name="Коэффицент" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_PAY_PARAMETR"><Map Name="PayParametrID" Column="PayParametrID"></Map><Map Name="PayParametrGroup" Column="PayParametrGroup"></Map><Map Name="Name" Column="Name"></Map><Map Name="IsMonthSplit" Column="IsMonthSplit"></Map><Map Name="ParametrOrder" Column="ParametrOrder"></Map><Map Name="PayParametrMain" Column="PayParametrMain"></Map><Map Name="DependType" Column="DependType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PAY_PARAMETR'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PAY_PARAMETR_GROUP',NULL,'Primary SQL Server','Группа параметров',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группа параметров',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PAY_PARAMETR_GROUP" Description="Группа параметров" PrimaryKey="PayParametrGroupID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="PayParametrGroupID" Index="5030001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5030002" Description="Наменование" Required="1"></Attribute><Child Name="PayParameters" Index="5030003" Type="FIES.PAY_PARAMETR" Description="Параметры" ChildAttribute="PayParametrGroup" SortingAttr="ParametrOrder"></Child></Fields><DbMapping><Table name="T_PAY_PARAMETR_GROUP"><Map Name="PayParametrGroupID" Column="PayParametrID"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_SERVICE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PAY_PARAMETR_SERVICE',NULL,'Primary SQL Server','Параметр оплаты услуги',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр оплаты услуги',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_SERVICE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PAY_PARAMETR_SERVICE" Description="Параметр оплаты услуги" PrimaryKey="PayParametrServiceID" DNAttributes="{PayParametr/Name}" DisplayName="{0}"><Fields><Attribute Name="PayParametrServiceID" Index="5060001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="PayCategory" Index="5060002" Type="FIES.PAY_CATEGORY" Description="Категория" Required="1"></Parent><Parent Name="PayParametr" Index="5060003" Type="FIES.PAY_PARAMETR" Description="Параметр" Required="1"></Parent><Parent Name="MedicalService" Index="5060004" Type="FIES.MEDICAL_SERVICE" Description="Услуга по справочнику"></Parent></Fields><DbMapping><Table name="T_PAY_PARAMETR_SERVICE"><Map Name="PayParametrServiceID" Column="PayParametrServiceID"></Map><Map Name="PayCategory" Column="PayCategory"></Map><Map Name="PayParametr" Column="PayParametr"></Map><Map Name="MedicalService" Column="MedicalService"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PAY_PARAMETR_SERVICE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SMO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SMO',NULL,'Primary SQL Server','Единый реестр страховых медицинских организаций, осуществляющих деятельность в сфере обязательного медицинского страхования',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Единый реестр страховых медицинских организаций, осуществляющих деятельность в сфере обязательного медицинского страхования',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='SMO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SMO" Description="Единый реестр страховых медицинских организаций, осуществляющих деятельность в сфере обязательного медицинского страхования" PrimaryKey="SMOCOD" DNAttributes="{NAM_SMFF}" DisplayName="{0}"><Fields><Attribute Name="TF_OKATO" Index="6970002" Type="string" Description="Код субъекта РФ по ОКАТО" CharacterMaximumLength="5" Required="1"></Attribute><Attribute Name="SMOCOD" Index="6970003" Type="string" Description="Код CМО" CharacterMaximumLength="5" Required="1"></Attribute><Attribute Name="NAM_SMOP" Index="6970004" Type="string" Description="Наименование CМО полное" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="NAM_SMOK" Index="6970005" Type="string" Description="Наименование CМО краткое" CharacterMaximumLength="250" Required="1"></Attribute><Attribute Name="INN" Index="6970006" Type="string" Description="ИНН" CharacterMaximumLength="12" Required="1"></Attribute><Attribute Name="OGRN" Index="6970007" Type="string" Description="ОГРН" CharacterMaximumLength="15" Required="1"></Attribute><Attribute Name="KPP" Index="6970008" Type="string" Description="КПП" CharacterMaximumLength="9" Required="1"></Attribute><Attribute Name="INDEX_J" Index="6970009" Type="string" Description="Почтовый индекс юридического адреса CМО" CharacterMaximumLength="6"></Attribute><Attribute Name="ADDR_J" Index="6970010" Type="string" Description="Юридический адрес CМО" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="FAM_RUK" Index="6970014" Type="string" Description="Фамилия руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="IM_RUK" Index="6970015" Type="string" Description="Имя руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="OT_RUK" Index="6970016" Type="string" Description="Отчество руководителя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="PHONE" Index="6970017" Type="string" Description="Телефон" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="FAX" Index="6970018" Type="string" Description="Факс" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="E_MAIL" Index="6970019" Type="string" Description="Адрес электронной почты" CharacterMaximumLength="50" Required="1"></Attribute><Attribute Name="N_DOC" Index="6970020" Type="string" Description="Номер лицензии" CharacterMaximumLength="20" Required="1"></Attribute><Attribute Name="D_START" Index="6970021" Type="date" Description="Дата начала действия лицензии" Required="1"></Attribute><Attribute Name="DATA_E" Index="6970022" Type="date" Description="Дата окончания действия лицензии"></Attribute><Attribute Name="WWW" Index="6970024" Type="string" Description="Адрес сайта в сети интернет" CharacterMaximumLength="100"></Attribute><Attribute Name="D_BEGIN" Index="6970025" Type="date" Description="Дата включения в реестр СМО"></Attribute><Attribute Name="D_END" Index="6970026" Type="date" Description="Дата исключения из реестра СМО"></Attribute><Attribute Name="NAME_E" Index="6970027" Type="string" Description="Причина исключения СМО из реестра СМО" CharacterMaximumLength="10"></Attribute><Attribute Name="DUVED" Index="6970028" Type="date" Description="Дата уведомления об осуществлении деятельности в сфере ОМС"></Attribute><Attribute Name="D_EDIT" Index="6970029" Type="date" Description="Дата последнего редактирования"></Attribute><Attribute Name="INDEX_F" Index="6970030" Type="string" Description="Почтовый индекс фактического адреса" CharacterMaximumLength="6"></Attribute><Attribute Name="ADDR_F" Index="6970031" Description="Фактический адрес СМО" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="NAL_P" Index="6970032" Type="string" Description="Наличие действующих полисов ОМС" CharacterMaximumLength="1"></Attribute><Attribute Name="KOL_ZL" Index="6970033" Type="int" Description="Численность за-страхованных лиц в СМО" Required="1"></Attribute><Attribute Name="IsActive" Index="6970034" Type="bool" Description="Активно" Required="1"></Attribute><Attribute Name="ShortFIODative" Index="6970035" Type="string" Description="ФИО в дательном падеже кратко" CharacterMaximumLength="50"></Attribute><Attribute Name="ShortName" Index="6970036" Type="string" Description="Кодовое название" CharacterMaximumLength="20" Required="1"></Attribute><Attribute Name="NAM_SMFF" Index="6970037" Type="string" Description="Наименование CМО в свободной форме" CharacterMaximumLength="250" Required="1"></Attribute><Parent Name="OKOPF" Index="6970011" Type="FIES.O005_OKOPF" Description="ОКОПФ"></Parent><Choice Name="ORG" Index="6970013" Description="Признак подчиненности" Required="1"><Item Name="Головная организация" Index="1"></Item><Item Name="Филиал" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_SMO"><Map Name="TF_OKATO" Column="TF_OKATO"></Map><Map Name="SMOCOD" Column="SMOCOD"></Map><Map Name="NAM_SMOP" Column="NAM_SMOP"></Map><Map Name="NAM_SMOK" Column="NAM_SMOK"></Map><Map Name="NAM_SMFF" Column="NAM_SMFF"></Map><Map Name="INN" Column="INN"></Map><Map Name="OGRN" Column="OGRN"></Map><Map Name="KPP" Column="KPP"></Map><Map Name="INDEX_J" Column="INDEX_J"></Map><Map Name="ADDR_J" Column="ADDR_J"></Map><Map Name="OKOPF" Column="OKOPF"></Map><Map Name="ORG" Column="ORG"></Map><Map Name="FAM_RUK" Column="FAM_RUK"></Map><Map Name="IM_RUK" Column="IM_RUK"></Map><Map Name="OT_RUK" Column="OT_RUK"></Map><Map Name="PHONE" Column="PHONE"></Map><Map Name="FAX" Column="FAX"></Map><Map Name="E_MAIL" Column="E_MAIL"></Map><Map Name="N_DOC" Column="N_DOC"></Map><Map Name="D_START" Column="D_START"></Map><Map Name="DATA_E" Column="DATA_E"></Map><Map Name="WWW" Column="WWW"></Map><Map Name="D_BEGIN" Column="D_BEGIN"></Map><Map Name="D_END" Column="D_END"></Map><Map Name="NAME_E" Column="NAME_E"></Map><Map Name="DUVED" Column="DUVED"></Map><Map Name="D_EDIT" Column="D_EDIT"></Map><Map Name="INDEX_F" Column="INDEX_F"></Map><Map Name="ADDR_F" Column="ADDR_F"></Map><Map Name="NAL_P" Column="NAL_P"></Map><Map Name="KOL_ZL" Column="KOL_ZL"></Map><Map Name="IsActive" Column="IsActive"></Map><Map Name="ShortFIODative" Column="ShortFIODative"></Map><Map Name="ShortName" Column="ShortName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SMO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TFOMS_BRANCH',NULL,'Primary SQL Server','Филиал ТФОМС',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Филиал ТФОМС',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="TFOMS_BRANCH" Description="Филиал ТФОМС" PrimaryKey="TfomsBranchID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="TfomsBranchID" Index="5320001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="BranchCode" Index="5320002" Type="string" Description="Код филиала" CharacterMaximumLength="8" Required="1"></Attribute><Attribute Name="Name" Index="5320003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="DateAdd" Index="5320004" Type="date" Description="Дата включения в справочник" Required="1"></Attribute><Attribute Name="DateRemove" Index="5320005" Type="date" Description="Дата исключения из справочника"></Attribute><Attribute Name="AddressString" Index="5320006" Type="string" Description="Адрес-строка"></Attribute><Attribute Name="NameFull" Index="5320007" Type="string" Description="Полное наименование"></Attribute><Attribute Name="RegistryPhones" Index="5320008" Type="string" Description="Контактные телефоны"></Attribute><Attribute Name="IsActive" Index="5320009" Type="bool" Description="Активный" Required="1"></Attribute><Child Name="TfomsBranchMos" Index="5320010" Type="FIES.TFOMS_BRANCH_MO" Description="Связь филиала ТФОМС с МО" ChildAttribute="TfomsBranch"></Child></Fields><DbMapping><Table name="T_TFOMS_BRANCH"><Map Name="TfomsBranchID" Column="TfomsBranchID"></Map><Map Name="BranchCode" Column="BranchCode"></Map><Map Name="Name" Column="Name"></Map><Map Name="DateAdd" Column="DateAdd"></Map><Map Name="DateRemove" Column="DateRemove"></Map><Map Name="AddressString" Column="AddressString"></Map><Map Name="NameFull" Column="NameFull"></Map><Map Name="RegistryPhones" Column="RegistryPhones"></Map><Map Name="IsActive" Column="IsActive"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH_MO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TFOMS_BRANCH_MO',NULL,'Primary SQL Server','Связь филиала ТФОМС с МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь филиала ТФОМС с МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH_MO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="TFOMS_BRANCH_MO" Description="Связь филиала ТФОМС с МО" PrimaryKey="TfomsBranchMoID"><Fields><Attribute Name="TfomsBranchMoID" Index="5330001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="TfomsBranch" Index="5330002" Type="FIES.TFOMS_BRANCH" Description="Филиал ТФОМС" Required="1"></Parent><Parent Name="Mo" Index="5330003" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent></Fields><DbMapping><Table name="T_TFOMS_BRANCH_MO"><Map Name="TfomsBranchMoID" Column="TfomsBranchMoID"></Map><Map Name="TfomsBranch" Column="TfomsBranch"></Map><Map Name="Mo" Column="Mo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='TFOMS_BRANCH_MO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V002_PROFILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V002_PROFILE',NULL,'Primary SQL Server','Классификатор профилей оказанной медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор профилей оказанной медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V002_PROFILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V002_PROFILE" Description="Классификатор профилей оказанной медицинской помощи" PrimaryKey="IDPR" DNAttributes="{PRNAME}" DisplayName="{0}"><Fields><Attribute Name="IDPR" Index="7040001" Type="int" Description="Код" Required="1"></Attribute><Attribute Name="PRNAME" Index="7040002" Type="string" Description="Наименование" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="DATEBEG" Index="7040003" Type="date" Description="Дата начала действия записи" Required="1"></Attribute><Attribute Name="DATEEND" Index="7040004" Type="date" Description="Дата окончания действия записи"></Attribute><Attribute Name="RegionalCode" Index="7040005" Type="string" Description="Дополнительный код" CharacterMaximumLength="50"></Attribute><Attribute Name="RegionalName" Index="7040006" Type="string" Description="Дополнительное наименование" CharacterMaximumLength="100"></Attribute></Fields><DbMapping><Table name="T_V002_PROFILE"><Map Name="IDPR" Column="IDPR"></Map><Map Name="PRNAME" Column="PRNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="RegionalCode" Column="RegionalCode"></Map><Map Name="RegionalName" Column="RegionalName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V002_PROFILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V006_MEDICAL_TERMS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V006_MEDICAL_TERMS',NULL,'Primary SQL Server','Классификатор условий оказания медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор условий оказания медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V006_MEDICAL_TERMS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V006_MEDICAL_TERMS" Description="Классификатор условий оказания медицинской помощи" PrimaryKey="IDUMP" DNAttributes="{UMPNAME}" DisplayName="{0}"><Fields><Attribute Name="IDUMP" Index="7010001" Type="int" Description="Код"></Attribute><Attribute Name="UMPNAME" Index="7010002" Type="string" Description="Наименование условия" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="DATEBEG" Index="7010003" Type="date" Description="Дата начала действия записи" Required="1"></Attribute><Attribute Name="DATEEND" Index="7010004" Type="date" Description="Дата окончания действия записи"></Attribute><Attribute Name="OtherCode" Index="7010005" Type="int" Description="Альтернативный код"></Attribute><Attribute Name="RegionalCode" Index="7010006" Type="string" Description="Региональный код" CharacterMaximumLength="50"></Attribute></Fields><DbMapping><Table name="T_V006_MEDICAL_TERMS"><Map Name="IDUMP" Column="IDUMP"></Map><Map Name="UMPNAME" Column="UMPNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="OtherCode" Column="OtherCode"></Map><Map Name="RegionalCode" Column="RegionalCode"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V006_MEDICAL_TERMS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V008_MEDICAL_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V008_MEDICAL_TYPE',NULL,'Primary SQL Server','Классификатор видов медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор видов медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V008_MEDICAL_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V008_MEDICAL_TYPE" Description="Классификатор видов медицинской помощи" PrimaryKey="IDVMP" DNAttributes="{VMPNAME}" DisplayName="{0}"><Fields><Attribute Name="IDVMP" Index="7030001" Type="int" Description="Код"></Attribute><Attribute Name="VMPNAME" Index="7030002" Type="string" Description="Наименование" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="DATEBEG" Index="7030003" Type="date" Description="Дата начала действия записи" Required="1"></Attribute><Attribute Name="DATEEND" Index="7030004" Type="date" Description="Дата окончания действия записи"></Attribute><Attribute Name="RegionalCode" Index="7030005" Type="string" Description="Региональный код" CharacterMaximumLength="50"></Attribute></Fields><DbMapping><Table name="T_V008_MEDICAL_TYPE"><Map Name="IDVMP" Column="IDVMP"></Map><Map Name="VMPNAME" Column="VMPNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="RegionalCode" Column="RegionalCode"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V008_MEDICAL_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V010_PAY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V010_PAY',NULL,'Primary SQL Server','Классификатор способов оплаты медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор способов оплаты медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V010_PAY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V010_PAY" Description="Классификатор способов оплаты медицинской помощи" PrimaryKey="IDSP" DNAttributes="{SPNAME}" DisplayName="{0}"><Fields><Attribute Name="IDSP" Index="7090001" Type="int" Description="Код способа оплаты медицинской помощи"></Attribute><Attribute Name="SPNAME" Index="7090002" Type="string" Description="Наименование способа оплаты медицинской помощи" CharacterMaximumLength="254" Required="1"></Attribute><Attribute Name="DATEBEG" Index="7090003" Type="date" Description="Дата начала действия записи" Required="1"></Attribute><Attribute Name="DATEEND" Index="7090004" Type="date" Description="Дата окончания действия записи "></Attribute><Attribute Name="OtherCode" Index="7090005" Type="int" Description="Альтернативный код"></Attribute></Fields><DbMapping><Table name="T_V010_PAY"><Map Name="IDSP" Column="IDSP"></Map><Map Name="SPNAME" Column="SPNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="OtherCode" Column="OtherCode"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V010_PAY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V018_VMP_TYPE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V018_VMP_TYPE',NULL,'Primary SQL Server','Классификатор видов высокотехнологичной медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор видов высокотехнологичной медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V018_VMP_TYPE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V018_VMP_TYPE" Description="Классификатор видов высокотехнологичной медицинской помощи" PrimaryKey="IDHVID" DNAttributes="{IDHVID};{HVIDNAME}" DisplayName="{0} - {1}"><Fields><Attribute Name="IDHVID" Index="5690001" Type="string" Description="Код вида ВМП" CharacterMaximumLength="12"></Attribute><Attribute Name="HVIDNAME" Index="5690002" Type="string" Description="Наименование вида ВМП" CharacterMaximumLength="500" Required="1"></Attribute><Attribute Name="DATEBEG" Index="5690003" Type="date" Description="Дата начала"></Attribute><Attribute Name="DATEEND" Index="5690004" Type="date" Description="Дата окончания"></Attribute><Attribute Name="FinNorm" Index="5690006" Type="float" Description="Норматив финансовых затрат на единицу объема" NumericPrecision="20" NumericScale="2"></Attribute><Child Name="V019VmpMethods" Index="5690007" Type="FIES.V019_VMP_METHOD" Description="Классификатор методов высокотехнологичной медицинской помощи" ChildAttribute="HVID" SortingAttr="IDHM"></Child></Fields><DbMapping><Table name="T_V018_VMP_TYPE"><Map Name="IDHVID" Column="IDHVID"></Map><Map Name="HVIDNAME" Column="HVIDNAME"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="FinNorm" Column="FinNorm"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V018_VMP_TYPE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='V019_VMP_METHOD')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'V019_VMP_METHOD',NULL,'Primary SQL Server','Классификатор методов высокотехнологичной медицинской помощи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Классификатор методов высокотехнологичной медицинской помощи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='V019_VMP_METHOD'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="V019_VMP_METHOD" Description="Классификатор методов высокотехнологичной медицинской помощи" PrimaryKey="IDHM" DNAttributes="{IDHM};{HMNAME}" DisplayName="{0} - {1}"><Fields><Attribute Name="IDHM" Index="6900001" Type="int" Description="Код метода ВМП"></Attribute><Attribute Name="HMNAME" Index="6900002" Type="string" Description="Наименование метода ВМП" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="DIAG" Index="6900003" Type="string" Description="МКБ" CharacterMaximumLength="1000"></Attribute><Attribute Name="DATEBEG" Index="6900005" Type="date" Description="Дата начала"></Attribute><Attribute Name="DATEEND" Index="6900006" Type="date" Description="Дата окончания"></Attribute><Attribute Name="HGR" Index="6900007" Type="int" Description="Номер группы высокотехнологичной медицинской помощи для данного метода"></Attribute><Attribute Name="HMODP" Index="6900008" Type="string" Description="Модель пациента для методов высокотехнологичной медицинской помощи" CharacterMaximumLength="1000"></Attribute><Attribute Name="TreatmentType" Index="6900009" Type="text" Description="Вид лечения"></Attribute><Parent Name="HVID" Index="6900004" Type="FIES.V018_VMP_TYPE" Description="Вид ВМП" CharacterMaximumLength="12"></Parent></Fields><DbMapping><Table name="T_V019_VMP_METHOD"><Map Name="IDHM" Column="IDHM"></Map><Map Name="HMNAME" Column="HMNAME"></Map><Map Name="DIAG" Column="DIAG"></Map><Map Name="HVID" Column="HVID"></Map><Map Name="DATEBEG" Column="DATEBEG"></Map><Map Name="DATEEND" Column="DATEEND"></Map><Map Name="HGR" Column="HGR"></Map><Map Name="HMODP" Column="HMODP"></Map></Table><Table name="T_V019_VMP_METHOD"><Map Name="TreatmentType" Column="TreatmentType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='V019_VMP_METHOD'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='LIMIT_VALUE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'LIMIT_VALUE',NULL,'Primary SQL Server','Значение лимита',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение лимита',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='LIMIT_VALUE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="LIMIT_VALUE" Description="Значение лимита" PrimaryKey="LimitValueID"><Fields><Attribute Name="LimitValueID" Index="5470001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="LimitValue" Index="5470004" Type="float" Description="Значение лимита" NumericPrecision="20" NumericScale="6" DefaultFormat="{0:0.######}" Required="1"></Attribute><Parent Name="PlanItemLimits" Index="5470002" Type="FIES.PLAN_ITEM_LIMITS" Description="Лимит на заявки" Required="1"></Parent><Parent Name="PlanLimitType" Index="5470005" Type="FIES.PLAN_LIMIT_TYPE" Description="Тип лимита"></Parent><Parent Name="ParameterGroup" Index="5470006" Type="FIES.PARAMETER_GROUP" Description="Группа параметров" Required="1"></Parent></Fields><DbMapping><Table name="T_LIMIT_VALUE"><Map Name="LimitValueID" Column="LimitValueID"></Map><Map Name="PlanItemLimits" Column="PlanItemLimits"></Map><Map Name="LimitValue" Column="LimitValue"></Map><Map Name="PlanLimitType" Column="PlanLimitType"></Map><Map Name="ParameterGroup" Column="ParameterGroup"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='LIMIT_VALUE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MONTH_VALUE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MONTH_VALUE',NULL,'Primary SQL Server','Значение по периоду',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение по периоду',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MONTH_VALUE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MONTH_VALUE" Description="Значение по периоду" PrimaryKey="MonthValueID"><Fields><Attribute Name="MonthValueID" Index="5070001" Type="string" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5070004" Type="float" Description="Значение" NumericPrecision="20" NumericScale="6" DefaultFormat="{0:0.######}"></Attribute><Parent Name="MonthValues" Index="5070002" Type="FIES.MONTH_VALUES" Description="Показатели по периодам" Required="1"></Parent><Parent Name="PeriodSection" Index="5070003" Type="FIES.PERIOD_SECTION" Description="Раздел периодов" Required="1"></Parent></Fields><DbMapping><Table name="V_MONTH_VALUE"><Map Name="MonthValueID" Column="MonthValueID"></Map><Map Name="MonthValues" Column="MonthValues"></Map><Map Name="PeriodSection" Column="PeriodSection"></Map><Map Name="Value" Column="Value"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MONTH_VALUE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MONTH_VALUES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MONTH_VALUES',NULL,'Primary SQL Server','Показатели по периодам',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Показатели по периодам',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MONTH_VALUES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MONTH_VALUES" Description="Показатели по периодам" PrimaryKey="MonthValuesID"><Fields><Attribute Name="MonthValuesID" Index="6000001" Type="guid" Description="Идентификатор"></Attribute><Child Name="MonthValues" Index="6000002" Type="FIES.MONTH_VALUE" Description="Значения по периодам" ChildAttribute="MonthValues"></Child></Fields><DbMapping><Table name="T_MONTH_VALUES"><Map Name="MonthValuesID" Column="MonthValuesID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MONTH_VALUES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN',NULL,'Primary SQL Server','План',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='План',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN" Description="План" PrimaryKey="PlanID" DNAttributes="{PlanPeriod/Year};{Mo/NAM_MOK}" DisplayName="[{0}] - {1}"><Fields><Attribute Name="PlanID" Index="5390001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Mo" Index="5390004" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent><Parent Name="PlanPeriod" Index="5390006" Type="FIES.PLAN_PERIOD" Description="Отчётный период" Required="1"></Parent><Child Name="PlanItems" Index="5390005" Type="FIES.PLAN_ITEM" Description="Записи плана" ChildAttribute="Plan"></Child></Fields><DbMapping><Table name="T_PLAN"><Map Name="PlanID" Column="PlanID"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="PlanPeriod" Column="PlanPeriod"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_ITEM',NULL,'Primary SQL Server','Запись плана',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Запись плана',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_ITEM" Description="Запись плана" PrimaryKey="PlanItemID"><Fields><Attribute Name="PlanItemID" Index="5410001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Plan" Index="5410002" Type="FIES.PLAN" Description="План" Required="1"></Parent><Child Name="PlanValues" Index="5410003" Type="FIES.PLAN_VALUE" Description="Значения параметров" ChildAttribute="PlanItem"></Child><Child Name="PlanValueProposals" Index="5410008" Type="FIES.PLAN_VALUE_PROPOSAL" Description="Значения в предложении МО" ChildAttribute="PlanItem"></Child><Choice Name="Status" Index="5410006" Description="Статус" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден" Index="2"></Item><Item Name="Не утвержден" Index="3"></Item></Choice><Link Name="PlanNote" Index="5410005" Type="FIES.PLAN_NOTE" Description="Замечание" LinkAttribute="PlanItem"></Link></Fields><DbMapping><Table name="T_PLAN_ITEM"><Map Name="PlanItemID" Column="PlanItemID"></Map><Map Name="Plan" Column="[Plan]"></Map><Map Name="Status" Column="Status"></Map></Table></DbMapping><CalculatingAttributes><Parent Name="MonthValues" Index="5410004" Type="FIES.MONTH_VALUES" Description="Показатели по периодам (Итог)" PathAttributes="{PlanValues}" RequiredAttributes="{PlanValues/PlanItemMonthValues/All}"></Parent><Child Name="PlanValueSmos" Index="5410007" Type="FIES.PLAN_VALUE_SMO" Description="Значения по периодам по СМО" PathAttributes="{PlanValues/PlanValueSmos}" RequiredAttributes="{PlanValues/PlanValueSmos/Value}"></Child></CalculatingAttributes></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_ITEM_LIMITS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_ITEM_LIMITS',NULL,'Primary SQL Server','Лимиты на заявки',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Лимиты на заявки',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_ITEM_LIMITS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_ITEM_LIMITS" Description="Лимиты на заявки" PrimaryKey="PlanItemLimitsID"><Fields><Attribute Name="PlanItemLimitsID" Index="5460001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Mo" Index="5460002" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent><Parent Name="PlanPeriod" Index="5460004" Type="FIES.PLAN_PERIOD" Description="Отчётный период" Required="1"></Parent><Parent Name="Subprogramm" Index="5460006" Type="FIES.SUBPROGRAMM" Description="Подпрограмма"></Parent><Child Name="LimitValues" Index="5460005" Type="FIES.LIMIT_VALUE" Description="Значение лимита" ChildAttribute="PlanItemLimits"></Child></Fields><DbMapping><Table name="T_PLAN_ITEM_LIMITS"><Map Name="PlanItemLimitsID" Column="PlanItemLimitsID"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="PlanPeriod" Column="PlanPeriod"></Map><Map Name="Subprogramm" Column="Subprogramm"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_ITEM_LIMITS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_ITEM_MONTH_VALUES',NULL,'Primary SQL Server','Разбивка по периодам',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Разбивка по периодам',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_ITEM_MONTH_VALUES" Description="Разбивка по периодам" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="PlanValue" Index="5450001" Type="FIES.PLAN_VALUE" Description="Значение годового параметра" Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_ITEM_MONTH_VALUES"><Map Name="PlanValue" Column="PlanValue"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES_SMO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_ITEM_MONTH_VALUES_SMO',NULL,'Primary SQL Server','Разбивка по периодам в СМО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Разбивка по периодам в СМО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES_SMO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_ITEM_MONTH_VALUES_SMO" Description="Разбивка по периодам в СМО" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="PlanValueSmo" Index="5560001" Type="FIES.PLAN_VALUE_SMO" Description="Значение годового параметра по СМО" Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_ITEM_MONTH_VALUES_SMO"><Map Name="PlanValueSmo" Column="PlanValueSmo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_ITEM_MONTH_VALUES_SMO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_ITEM_SMO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_ITEM_SMO',NULL,'Primary SQL Server','Заявка плана СМО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Заявка плана СМО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_ITEM_SMO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_ITEM_SMO" Description="Заявка плана СМО" PrimaryKey="PlanItemSmoID"><Fields><Attribute Name="PlanItemSmoID" Index="5610001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="SmoPlanRequestStatus" Index="5610003" Type="FIES.SMO_PLAN_REQUEST_STATUS" Description="Статус заявки в СМО" Required="1"></Parent><Parent Name="PlanItem" Index="5610006" Type="FIES.PLAN_ITEM" Description="Запись плана" Required="1"></Parent><Child Name="PlanValueSmos" Index="5610004" Type="FIES.PLAN_VALUE_SMO" Description="Значение параметра" ChildAttribute="PlanItemSmo" RemoveAction="1"></Child><Choice Name="SmoStatus" Index="5610002" Description="Статус утверждения в СМО" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден" Index="2"></Item><Item Name="Не утвержден" Index="3"></Item></Choice><Link Name="PlanNote" Index="5610005" Type="FIES.PLAN_NOTE" Description="Замечание на заявку" LinkAttribute="PlanItemSmo"></Link></Fields><DbMapping><Table name="T_PLAN_ITEM_SMO"><Map Name="PlanItemSmoID" Column="PlanItemSmoID"></Map><Map Name="SmoStatus" Column="SmoStatus"></Map><Map Name="SmoPlanRequestStatus" Column="SmoPlanRequestStatus"></Map><Map Name="PlanItem" Column="PlanItem"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_ITEM_SMO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_NOTE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_NOTE',NULL,'Primary SQL Server','Замечание на заявку',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Замечание на заявку',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_NOTE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_NOTE" Description="Замечание на заявку" PrimaryKey="PlanNoteID"><Fields><Attribute Name="PlanNoteID" Index="5540001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="NoteText" Index="5540002" Type="text" Description="Текст замечания" Required="1"></Attribute><Parent Name="Users" Index="5540003" Type="FIES.USERS" Description="Пользователь системы"></Parent><Parent Name="PlanRequest" Index="5540004" Type="FIES.PLAN_REQUEST" Description="Заявка"></Parent><Parent Name="PlanItem" Index="5540005" Type="FIES.PLAN_ITEM" Description="Запись заявки"></Parent><Parent Name="PlanValue" Index="5540006" Type="FIES.PLAN_VALUE" Description="Значение параметра"></Parent><Parent Name="PlanItemSmo" Index="5540007" Type="FIES.PLAN_ITEM_SMO" Description="Заявка плана СМО"></Parent></Fields><DbMapping><Table name="T_PLAN_NOTE"><Map Name="PlanNoteID" Column="PlanNoteID"></Map><Map Name="NoteText" Column="NoteText"></Map><Map Name="Users" Column="Users"></Map><Map Name="PlanRequest" Column="PlanRequest"></Map><Map Name="PlanItem" Column="PlanItem"></Map><Map Name="PlanValue" Column="PlanValue"></Map><Map Name="PlanItemSmo" Column="PlanItemSmo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_NOTE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_PERIOD')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_PERIOD',NULL,'Primary SQL Server','Отчётный период',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отчётный период',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_PERIOD'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_PERIOD" Description="Отчётный период" PrimaryKey="PlanPeriodID" DNAttributes="{Year}" DisplayName="{0}"><Fields><Attribute Name="PlanPeriodID" Index="5500001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Year" Index="5500002" Type="int" Description="Год" Required="1"></Attribute></Fields><DbMapping><Table name="T_PLAN_PERIOD"><Map Name="PlanPeriodID" Column="PlanPeriodID"></Map><Map Name="Year" Column="Year"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_PERIOD'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST',NULL,'Primary SQL Server','Заявка на утверждение плановых показателей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Заявка на утверждение плановых показателей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST" Description="Заявка на утверждение плановых показателей" PrimaryKey="PlanID" DNAttributes="{PlanPeriod/Year};{Mo/NAM_MOK};{ObjectType/EntDesc};{Mo/MO_NUMBER}" DisplayName="{2}: {0}, {3} {1}" Inherits="FIES.PLAN"><Fields><Attribute Name="RequestDescription" Index="5400001" Type="string" Description="Примечание" CharacterMaximumLength="512"></Attribute><Attribute Name="Number" Index="5400004" Type="int" Description="Номер" Required="1"></Attribute><Attribute Name="RequestDate" Index="5400005" Type="date" Description="Дата отправки" DefaultFormat="{0:dd:MM:yyyy}"></Attribute><Attribute Name="RequestTime" Index="5400006" Type="datetime" Description="Время отправки" DefaultFormat="{0:HH:mm:ss}"></Attribute><Parent Name="RequestInProtocol" Index="5400013" Type="FIES.REQUEST_IN_PROTOCOL" Description="Протокол комиссии" Cashed="0"></Parent><Child Name="PlanRequestSmos" Index="5400008" Type="FIES.PLAN_REQUEST_SMO" Description="Настройки процентных соотношений по СМО" ChildAttribute="PlanRequest"></Child><Child Name="SmoPlanRequestStatuses" Index="5400009" Type="FIES.SMO_PLAN_REQUEST_STATUS" Description="Статус заявки в СМО" ChildAttribute="PlanRequest"></Child><Child Name="PlanRequestAttachmentFiles" Index="5400011" Type="FIES.PLAN_REQUEST_ATTACHMENT_FILE" Description="Прикрепленные документы" ChildAttribute="PlanRequest"></Child><Child Name="RequestInProtocols" Index="5400012" Type="FIES.REQUEST_IN_PROTOCOL" Description="Протоколыкомиссии" ChildAttribute="PlanRequest"></Child><Child Name="SplitSettingss" Index="5400015" Type="FIES.SPLIT_SETTINGS" Description="Настройки распределения" ChildAttribute="PlanRequest"></Child><Choice Name="YearStatus" Index="5400002" Description="Статус годовой разбивки" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден частично" Index="3"></Item><Item Name="Не утвержден" Index="4"></Item><Item Name="Утвержден" Index="5"></Item></Choice><Choice Name="PeriodStatus" Index="5400007" Description="Статус детализированной разбивки" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден частично" Index="3"></Item><Item Name="Не утвержден" Index="4"></Item><Item Name="Утвержден" Index="5"></Item></Choice><Choice Name="RequestType" Index="5400010" Description="Вид заявки" Save="0"><Item Name="Основная заявка" Index="558"></Item><Item Name="Корректирующая заявка" Index="559"></Item></Choice><Choice Name="PlanStatus" Index="5400014" Description="Статус"><Item Name="Предложение МО" Index="0"></Item><Item Name="План-задание" Index="1"></Item></Choice><Link Name="PlanNote" Index="5400003" Type="FIES.PLAN_NOTE" Description="Замечание на заявку" LinkAttribute="PlanRequest"></Link></Fields><DbMapping><Table name="T_PLAN_REQUEST"><Map Name="RequestDescription" Column="RequestDescription"></Map><Map Name="YearStatus" Column="Status"></Map><Map Name="Number" Column="Number"></Map><Map Name="RequestDate" Column="RequestDate"></Map><Map Name="RequestTime" Column="RequestTime"></Map><Map Name="PeriodStatus" Column="TfomsStatus"></Map></Table><Table name="T_PLAN"><Map Name="RequestType" Column="type_"></Map></Table><Lexem><Map Name="RequestInProtocol"><lx:QueryValue entity="REQUEST_IN_PROTOCOL" top="1" xmlns:lx="lexem"><condition><lx:Criteria type="And" xmlns:lx="lexem"><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5160002" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="5390001" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Path OwnerQueryLevel="1" xmlns:lx="lexem"><lx:StepInt index="5390001" xmlns:lx="lexem"></lx:StepInt></lx:Path></lx:Criterion></lx:Criteria></condition><orderBy><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5160003" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="5080003" xmlns:lx="lexem"></lx:StepInt></lx:Path><desc><![CDATA[True]]></desc></orderBy><value><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5160001" xmlns:lx="lexem"></lx:StepInt></lx:Path></value></lx:QueryValue></Map><Map Name="PlanStatus"><lx:Case xmlns:lx="lexem"><When><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5400013" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:BaseObjectOperand isNull="1" Entity="FIES.REQUEST_IN_PROTOCOL" xmlns:lx="lexem"></lx:BaseObjectOperand></lx:Criterion></When><Then><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[0]]></lx:ConstOperand></Then><Else><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[1]]></lx:ConstOperand></Else></lx:Case></Map></Lexem></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_ATTACHMENT_FILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST_ATTACHMENT_FILE',NULL,'Primary SQL Server','Прикрепленные документы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Прикрепленные документы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_ATTACHMENT_FILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST_ATTACHMENT_FILE" Description="Прикрепленные документы" Inherits="VCLib.FILE"><Fields><Attribute Name="PlanRequestAttachmentFileID" Index="5310001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CreationDateTime" Index="5310004" Type="datetime" Description="Дата создания файла" Required="1"></Attribute><Parent Name="PlanRequest" Index="5310002" Type="FIES.PLAN_REQUEST" Description="Заявка на утверждение плановых показателей" Required="1"></Parent><Parent Name="Creator" Index="5310003" Type="VCLib.BASE_USERS" Description="Базовая сущность для пользователей системы." Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_REQUEST_ATTACHMENT_FILE"><Map Name="PlanRequestAttachmentFileID" Column="PlanRequestAttachmentFileID"></Map><Map Name="PlanRequest" Column="PlanRequest"></Map><Map Name="Creator" Column="Creator"></Map><Map Name="CreationDateTime" Column="CreationDateTime"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_ATTACHMENT_FILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_CORRECT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST_CORRECT',NULL,'Primary SQL Server','Дополнительная (корректирующая) заявка',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN_REQUEST'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Дополнительная (корректирующая) заявка',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN_REQUEST') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_CORRECT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST_CORRECT" Description="Дополнительная (корректирующая) заявка" Inherits="FIES.PLAN_REQUEST"><Fields></Fields></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_CORRECT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_MAIN')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST_MAIN',NULL,'Primary SQL Server','Основная (годовая) заявка',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN_REQUEST'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Основная (годовая) заявка',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'PLAN_REQUEST') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_MAIN'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST_MAIN" Description="Основная (годовая) заявка" Inherits="FIES.PLAN_REQUEST"><Fields></Fields></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_MAIN'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST_SMO',NULL,'Primary SQL Server','Настройка процентного соотношения плановых объемов по СМО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка процентного соотношения плановых объемов по СМО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST_SMO" Description="Настройка процентного соотношения плановых объемов по СМО" PrimaryKey="PlanRequestSmoID"><Fields><Attribute Name="PlanRequestSmoID" Index="5620001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="PlanRequest" Index="5620002" Type="FIES.PLAN_REQUEST" Description="Заявка" Required="1"></Parent><Parent Name="Smo" Index="5620003" Type="FIES.SMO" Description="СМО" CharacterMaximumLength="5" Required="1"></Parent><Child Name="PlanRequestSmoItems" Index="5620004" Type="FIES.PLAN_REQUEST_SMO_ITEM" Description="Значения процентных соотношений" ChildAttribute="PlanRequestSmo"></Child></Fields><DbMapping><Table name="T_PLAN_REQUEST_SMO"><Map Name="PlanRequestSmoID" Column="PlanRequestSmoID"></Map><Map Name="PlanRequest" Column="PlanRequest"></Map><Map Name="Smo" Column="Smo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_REQUEST_SMO_ITEM',NULL,'Primary SQL Server','Значения процентных соотношений по СМО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значения процентных соотношений по СМО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_REQUEST_SMO_ITEM" Description="Значения процентных соотношений по СМО" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="PlanRequestSmo" Index="5630002" Type="FIES.PLAN_REQUEST_SMO" Description="Настройка по СМО" Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_REQUEST_SMO_ITEM"><Map Name="PlanRequestSmo" Column="PlanRequestSmo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_REQUEST_SMO_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_VALUE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_VALUE',NULL,'Primary SQL Server','Значение параметра',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение параметра',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_VALUE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_VALUE" Description="Значение параметра" PrimaryKey="PlanValueID"><Fields><Attribute Name="PlanValueID" Index="5440001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5440004" Type="float" Description="Значение" NumericPrecision="20" NumericScale="6" DefaultFormat="{0:0.######}"></Attribute><Attribute Name="RequestValue" Index="5440009" Type="float" Description="Значение из предложения МО" NumericPrecision="20" NumericScale="6" DefaultFormat="{0:0.######}"></Attribute><Parent Name="PlanParameter" Index="5440002" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="PlanItem" Index="5440003" Type="FIES.PLAN_ITEM" Description="Запись плана" Required="1"></Parent><Child Name="PlanValueSmos" Index="5440006" Type="FIES.PLAN_VALUE_SMO" Description="Значения параметров по СМО" ChildAttribute="PlanValue"></Child><Choice Name="TfomsStatus" Index="5440007" Description="Статус утверждения в ТФОМС" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден" Index="2"></Item><Item Name="Не утвержден" Index="3"></Item></Choice><Link Name="PlanItemMonthValues" Index="5440005" Type="FIES.PLAN_ITEM_MONTH_VALUES" Description="Разбивка по периодам" LinkAttribute="PlanValue"></Link><Link Name="PlanNote" Index="5440008" Type="FIES.PLAN_NOTE" Description="Замечание" LinkAttribute="PlanValue"></Link></Fields><DbMapping><Table name="T_PLAN_VALUE"><Map Name="PlanValueID" Column="PlanValueID"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="PlanItem" Column="PlanItem"></Map><Map Name="Value" Column="Value"></Map><Map Name="TfomsStatus" Column="TfomsStatus"></Map></Table><Lexem><Map Name="RequestValue"><lx:Cast type="Decimal" xmlns:lx="lexem"><lx:ChildCount xmlns:lx="lexem"><condition><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5670003" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Path OwnerQueryLevel="1" xmlns:lx="lexem"><lx:StepInt index="5440002" xmlns:lx="lexem"></lx:StepInt></lx:Path></lx:Criterion></condition><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5440003" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="5410008" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Sum xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="5670002" xmlns:lx="lexem"></lx:StepInt></lx:Path></lx:Sum></lx:ChildCount></lx:Cast></Map></Lexem></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_VALUE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_VALUE_PROPOSAL')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_VALUE_PROPOSAL',NULL,'Primary SQL Server','Значение в преложении МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение в преложении МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_VALUE_PROPOSAL'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_VALUE_PROPOSAL" Description="Значение в преложении МО" PrimaryKey="PlanValueProposalID"><Fields><Attribute Name="PlanValueProposalID" Index="5670001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5670002" Type="float" Description="Значение" Required="1"></Attribute><Parent Name="PlanParameter" Index="5670003" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="PlanItem" Index="5670004" Type="FIES.PLAN_ITEM" Description="Запись плана" Required="1"></Parent></Fields><DbMapping><Table name="T_PLAN_VALUE_PROPOSAL"><Map Name="PlanValueProposalID" Column="PlanValueProposalID"></Map><Map Name="Value" Column="Value"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="PlanItem" Column="PlanItem"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_VALUE_PROPOSAL'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PLAN_VALUE_SMO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PLAN_VALUE_SMO',NULL,'Primary SQL Server','Значение параметра',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение параметра',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PLAN_VALUE_SMO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PLAN_VALUE_SMO" Description="Значение параметра" PrimaryKey="PlanValueSmoID"><Fields><Attribute Name="PlanValueSmoID" Index="5550001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5550004" Type="float" Description="Значение" NumericPrecision="20" NumericScale="6" DefaultFormat="{0:0.######}"></Attribute><Parent Name="Smo" Index="5550006" Type="FIES.SMO" Description="Страховая медицинская организация" CharacterMaximumLength="5" Required="1"></Parent><Parent Name="PlanValue" Index="5550007" Type="FIES.PLAN_VALUE" Description="Значение параметра" Required="1"></Parent><Parent Name="PlanItemSmo" Index="5550008" Type="FIES.PLAN_ITEM_SMO" Description="Заявка плана СМО"></Parent><Link Name="PlanItemMonthValuesSmo" Index="5550005" Type="FIES.PLAN_ITEM_MONTH_VALUES_SMO" Description="Разбивка по периодам по СМО" LinkAttribute="PlanValueSmo"></Link></Fields><DbMapping><Table name="T_PLAN_VALUE_SMO"><Map Name="PlanValueSmoID" Column="PlanValueSmoID"></Map><Map Name="Value" Column="Value"></Map><Map Name="Smo" Column="Smo"></Map><Map Name="PlanValue" Column="PlanValue"></Map><Map Name="PlanItemSmo" Column="PlanItemSmo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PLAN_VALUE_SMO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_DEFAULT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SMO_COEF_MONTH_VALUES_DEFAULT',NULL,'Primary SQL Server','Стандартные значения коэффициентов планов по СМО для МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Стандартные значения коэффициентов планов по СМО для МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_DEFAULT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SMO_COEF_MONTH_VALUES_DEFAULT" Description="Стандартные значения коэффициентов планов по СМО для МО" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="Smo" Index="5340001" Type="FIES.SMO" Description="Единый реестр страховых медицинских организаций, осуществляющих деятельность в сфере обязательного медицинского страхования" Required="1"></Parent><Parent Name="Mo" Index="5340002" Type="FIES.MO" Description="Медицинская организация" Required="1"></Parent></Fields><DbMapping><Table name="T_SMO_COEF_MONTH_VALUES_DEFAULT"><Map Name="Smo" Column="Smo"></Map><Map Name="Mo" Column="Mo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_DEFAULT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_EXCEPTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SMO_COEF_MONTH_VALUES_EXCEPTION',NULL,'Primary SQL Server','Исключения коэффициентов планов по СМО для МО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Исключения коэффициентов планов по СМО для МО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_EXCEPTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SMO_COEF_MONTH_VALUES_EXCEPTION" Description="Исключения коэффициентов планов по СМО для МО" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="Smo" Index="5350001" Type="FIES.SMO" Description="Единый реестр страховых медицинских организаций, осуществляющих деятельность в сфере обязательного медицинского страхования" Required="1"></Parent><Parent Name="Mo" Index="5350002" Type="FIES.MO" Description="Медицинская организация" Required="1"></Parent></Fields><DbMapping><Table name="T_SMO_COEF_MONTH_VALUES_EXCEPTION"><Map Name="Smo" Column="Smo"></Map><Map Name="Mo" Column="Mo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SMO_COEF_MONTH_VALUES_EXCEPTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SMO_PLAN_REQUEST_STATUS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SMO_PLAN_REQUEST_STATUS',NULL,'Primary SQL Server','Статус заявки в СМО',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Статус заявки в СМО',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='SMO_PLAN_REQUEST_STATUS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SMO_PLAN_REQUEST_STATUS" Description="Статус заявки в СМО" PrimaryKey="SmoPlanRequestStatusID" DNAttributes="{PlanRequest / DisplayName};{Smo/SMOCOD};{Smo/NAM_SMOK}" DisplayName="{0} ({1} {2})"><Fields><Attribute Name="SmoPlanRequestStatusID" Index="5010001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="SendDateTime" Index="5010006" Type="datetime" Description="Дата и время последней отправки заявки на рассмотрение"></Attribute><Parent Name="PlanRequest" Index="5010002" Type="FIES.PLAN_REQUEST" Description="Заявка на утверждение плановых показателей" Required="1"></Parent><Parent Name="Smo" Index="5010005" Type="FIES.SMO" Description="Страховая медицинская организация" CharacterMaximumLength="5" Required="1"></Parent><Child Name="PlanItemSmos" Index="5010007" Type="FIES.PLAN_ITEM_SMO" Description="Заявка плана СМО" ChildAttribute="SmoPlanRequestStatus"></Child><Choice Name="Status" Index="5010003" Description="Статус заявки" Required="1"><Item Name="Редактирование" Index="0"></Item><Item Name="На утверждении" Index="1"></Item><Item Name="Утвержден частично" Index="3"></Item><Item Name="Не утвержден" Index="4"></Item><Item Name="Утвержден" Index="5"></Item></Choice></Fields><DbMapping><Table name="T_SMO_PLAN_REQUEST_STATUS"><Map Name="SmoPlanRequestStatusID" Column="SmoPlanRequestStatusID"></Map><Map Name="PlanRequest" Column="PlanRequest"></Map><Map Name="Status" Column="Status"></Map><Map Name="Smo" Column="Smo"></Map><Map Name="SendDateTime" Column="SentDateTime"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SMO_PLAN_REQUEST_STATUS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='SPLIT_SETTINGS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SPLIT_SETTINGS',NULL,'Primary SQL Server','Настройка распределения плановых показателей внутри года',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка распределения плановых показателей внутри года',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='SPLIT_SETTINGS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="SPLIT_SETTINGS" Description="Настройка распределения плановых показателей внутри года" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="PlanRequest" Index="5710001" Type="FIES.PLAN_REQUEST" Description="Заявка"></Parent></Fields><DbMapping><Table name="T_SPLIT_SETTINGS"><Map Name="PlanRequest" Column="PlanRequest"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='SPLIT_SETTINGS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MEETING_MEMBER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MEETING_MEMBER',NULL,'Primary SQL Server','Реестр участников заседания комиссии',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Реестр участников заседания комиссии',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MEETING_MEMBER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MEETING_MEMBER" Description="Реестр участников заседания комиссии" PrimaryKey="MeetingMemberID"><Fields><Attribute Name="MeetingMemberID" Index="5170001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="LastName" Index="5170002" Type="string" Description="Фамилия" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="FirstName" Index="5170003" Type="string" Description="Имя" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="Patronymic" Index="5170004" Type="string" Description="Отчество" CharacterMaximumLength="40"></Attribute><Parent Name="Mo" Index="5170005" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6"></Parent></Fields><DbMapping><Table name="T_MEETING_MEMBER"><Map Name="MeetingMemberID" Column="MeetingMemberID"></Map><Map Name="LastName" Column="LastName"></Map><Map Name="FirstName" Column="FirstName"></Map><Map Name="Patronymic" Column="Patronymic"></Map><Map Name="Mo" Column="Mo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MEETING_MEMBER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MEETING_PROTOCOL')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MEETING_PROTOCOL',NULL,'Primary SQL Server','Протокол заседания комиссии',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Протокол заседания комиссии',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MEETING_PROTOCOL'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MEETING_PROTOCOL" Description="Протокол заседания комиссии" PrimaryKey="MeetingProtocolID" DNAttributes="{Number};{MeetingDate}" DisplayName="Протокол №{0} от {1:dd.MM.yyyy}"><Fields><Attribute Name="MeetingProtocolID" Index="5080001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Number" Index="5080002" Type="int" Description="Номер" Required="1"></Attribute><Attribute Name="MeetingDate" Index="5080003" Type="date" Description="Дата" Required="1"></Attribute><Attribute Name="IsApply" Index="5080008" Type="bool" Description="Подписан" Required="1"></Attribute><Parent Name="PlanPeriod" Index="5080004" Type="FIES.PLAN_PERIOD" Description="Отчётный период" Required="1"></Parent><Child Name="RequestsInProtocol" Index="5080005" Type="FIES.REQUEST_IN_PROTOCOL" Description="Заявка вошедшая в протокол комиссии" ChildAttribute="MeetingProtocol"></Child><Child Name="ProtocolMembers" Index="5080006" Type="FIES.PROTOCOL_MEMBER" Description="Участники заседания комиссии" ChildAttribute="MeetingProtocol"></Child></Fields><DbMapping><Table name="T_MEETING_PROTOCOL"><Map Name="MeetingProtocolID" Column="MeetingProtocolID"></Map><Map Name="Number" Column="Number"></Map><Map Name="MeetingDate" Column="MeetingDate"></Map><Map Name="PlanPeriod" Column="PlanPeriod"></Map><Map Name="IsApply" Column="IsApply"></Map></Table></DbMapping><CalculatingAttributes><Child Name="MeetingResolves" Index="5080007" Type="FIES.MEETING_RESOLVE" Description="Решения комиссии" PathAttributes="{RequestsInProtocol/MeetingResolves}" RequiredAttributes="{RequestsInProtocol/MeetingResolves}"></Child></CalculatingAttributes></Entity>' WHERE [Schema]='FIES' and EntName='MEETING_PROTOCOL'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='MEETING_RESOLVE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MEETING_RESOLVE',NULL,'Primary SQL Server','Решение комиссии',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Решение комиссии',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='MEETING_RESOLVE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="MEETING_RESOLVE" Description="Решение комиссии" PrimaryKey="MeetingResolveID"><Fields><Attribute Name="MeetingResolveID" Index="5190001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5190003" Type="float" Description="Значение" Required="1"></Attribute><Attribute Name="OldValue" Index="5190005" Type="float" Description="Значение из заявки" Required="1"></Attribute><Parent Name="RequestInProtocol" Index="5190002" Type="FIES.REQUEST_IN_PROTOCOL" Description="Заявка вошедшая в протокол комиссии"></Parent><Parent Name="PlanParameter" Index="5190004" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="Subprogramm" Index="5190006" Type="FIES.SUBPROGRAMM" Description="Подпрограмма"></Parent></Fields><DbMapping><Table name="T_MEETING_RESOLVE"><Map Name="MeetingResolveID" Column="MeetingResolveID"></Map><Map Name="RequestInProtocol" Column="RequestInProtocol"></Map><Map Name="Value" Column="Value"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="OldValue" Column="OldValue"></Map><Map Name="Subprogramm" Column="Subprogramm"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='MEETING_RESOLVE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PROTOCOL_MEMBER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PROTOCOL_MEMBER',NULL,'Primary SQL Server','Участник заседания комиссии',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Участник заседания комиссии',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PROTOCOL_MEMBER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PROTOCOL_MEMBER" Description="Участник заседания комиссии" PrimaryKey="ProtocolMemberID"><Fields><Attribute Name="ProtocolMemberID" Index="5660001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="MeetingProtocol" Index="5660002" Type="FIES.MEETING_PROTOCOL" Description="Протокол заседания комиссии" Required="1"></Parent><Parent Name="MeetingMember" Index="5660003" Type="FIES.MEETING_MEMBER" Description="Участник заседания комиссии" Required="1"></Parent></Fields><DbMapping><Table name="T_PROTOCOL_MEMBER"><Map Name="ProtocolMemberID" Column="ProtocolMemberID"></Map><Map Name="MeetingProtocol" Column="MeetingProtocol"></Map><Map Name="MeetingMember" Column="MeetingMember"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PROTOCOL_MEMBER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='REQUEST_IN_PROTOCOL')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REQUEST_IN_PROTOCOL',NULL,'Primary SQL Server','Заявка вошедшая в протокол комиссии',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Заявка вошедшая в протокол комиссии',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='REQUEST_IN_PROTOCOL'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="REQUEST_IN_PROTOCOL" Description="Заявка вошедшая в протокол комиссии" PrimaryKey="RequestInProtocolID"><Fields><Attribute Name="RequestInProtocolID" Index="5160001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="IsCoincide" Index="5160005" Type="bool" Description="Совпадает" Required="1"></Attribute><Parent Name="PlanRequest" Index="5160002" Type="FIES.PLAN_REQUEST" Description="Заявка" Required="1"></Parent><Parent Name="MeetingProtocol" Index="5160003" Type="FIES.MEETING_PROTOCOL" Description="Протокол заседания комиссии" Required="1"></Parent><Child Name="MeetingResolves" Index="5160004" Type="FIES.MEETING_RESOLVE" Description="Решения на комиссии" ChildAttribute="RequestInProtocol"></Child></Fields><DbMapping><Table name="T_REQUEST_IN_PROTOCOL"><Map Name="RequestInProtocolID" Column="RequestInProtocolID"></Map><Map Name="PlanRequest" Column="PlanRequest"></Map><Map Name="MeetingProtocol" Column="MeetingProtocol"></Map><Map Name="IsCoincide" Column="IsCoincide"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='REQUEST_IN_PROTOCOL'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='FACT_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'FACT_ITEM',NULL,'Primary SQL Server','Запись о выполнении плана',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Запись о выполнении плана',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='FACT_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="FACT_ITEM" Description="Запись о выполнении плана" PrimaryKey="FactItemID"><Fields><Attribute Name="FactItemID" Index="5360001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5360006" Type="float" Description="Значение" Required="1"></Attribute><Attribute Name="FactYear" Index="5360007" Type="int" Description="Год" Required="1"></Attribute><Attribute Name="ValueSum" Index="5360008" Type="float" Description="Значение суммы"></Attribute><Parent Name="Smo" Index="5360002" Type="FIES.SMO" Description="СМО" CharacterMaximumLength="5" Required="1"></Parent><Parent Name="Mo" Index="5360003" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent><Parent Name="PlanParameter" Index="5360004" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="PeriodSection" Index="5360005" Type="FIES.PERIOD_SECTION" Description="Раздел периодов" Required="1"></Parent></Fields><DbMapping><Table name="T_FACT_ITEM"><Map Name="FactItemID" Column="FactItemID"></Map><Map Name="Smo" Column="Smo"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="PeriodSection" Column="PeriodSection"></Map><Map Name="Value" Column="Value"></Map><Map Name="FactYear" Column="FactYear"></Map><Map Name="ValueSum" Column="ValueSum"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='FACT_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='FACT_ITEM_SUM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'FACT_ITEM_SUM',NULL,'Primary SQL Server','Запись о выполнении финансового плана',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Запись о выполнении финансового плана',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='FACT_ITEM_SUM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="FACT_ITEM_SUM" Description="Запись о выполнении финансового плана" PrimaryKey="FactItemSumID"><Fields><Attribute Name="FactItemSumID" Index="5730001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Value" Index="5730006" Type="float" Description="Значение" Required="1"></Attribute><Attribute Name="FactYear" Index="5730007" Type="int" Description="Год" Required="1"></Attribute><Parent Name="Smo" Index="5730002" Type="FIES.SMO" Description="СМО" CharacterMaximumLength="5" Required="1"></Parent><Parent Name="Mo" Index="5730003" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent><Parent Name="PlanParameter" Index="5730004" Type="FIES.PLAN_PARAMETER" Description="Параметр" Required="1"></Parent><Parent Name="PeriodSection" Index="5730005" Type="FIES.PERIOD_SECTION" Description="Раздел периодов" Required="1"></Parent></Fields><DbMapping><Table name="T_FACT_ITEM_SUM"><Map Name="FactItemSumID" Column="FactItemSumID"></Map><Map Name="Smo" Column="Smo"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="PlanParameter" Column="PlanParameter"></Map><Map Name="PeriodSection" Column="PeriodSection"></Map><Map Name="Value" Column="Value"></Map><Map Name="FactYear" Column="FactYear"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='FACT_ITEM_SUM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='ADDRESS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADDRESS',NULL,'Primary SQL Server','Адрес',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Адрес',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='ADDRESS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="ADDRESS" Description="Адрес" PrimaryKey="AddressID" DNAttributes="{Address}" DisplayName="{0}"><Fields><Attribute Name="AddressID" Index="5260001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="House" Index="5260004" Type="string" Description="Дом" CharacterMaximumLength="8"></Attribute><Attribute Name="Block" Index="5260005" Type="string" Description="Корпус" CharacterMaximumLength="8"></Attribute><Attribute Name="Flat" Index="5260006" Type="string" Description="Офис" CharacterMaximumLength="8"></Attribute><Attribute Name="ZIPCode" Index="5260008" Type="string" Description="Почтовый индекс" CharacterMaximumLength="10"></Attribute><Attribute Name="FreeAddressString" Index="5260009" Type="string" Description="Адрес в свободной форме" CharacterMaximumLength="256"></Attribute><Parent Name="City" Index="5260002" Type="FIES.CITY" Description="Населенный пункт" Required="1"></Parent><Parent Name="Street" Index="5260003" Type="FIES.STREET" Description="Улица"></Parent></Fields><DbMapping><Table name="T_ADDRESS"><Map Name="AddressID" Column="AddressID"></Map><Map Name="City" Column="City"></Map><Map Name="Street" Column="Street"></Map><Map Name="House" Column="House"></Map><Map Name="Block" Column="Block"></Map><Map Name="Flat" Column="Flat"></Map><Map Name="ZIPCode" Column="ZIPCode"></Map><Map Name="FreeAddressString" Column="FreeAddressString"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="Address" Index="5260007" Type="string" Description="Адрес" RequiredAttributes="{FreeAddressString};{House};{City/Name};{City/CityType};{Street/Name};{Street/StreetType};{Block};{Flat};{ZIPCode};{City/Rajon/Name};{City/Region/Name};{City/Country/Name};{Street/ZIPCode};{City/ZIPCode}"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='FIES' and EntName='ADDRESS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='CITY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CITY',NULL,'Primary SQL Server','Населенный пункт',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Населенный пункт',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='CITY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="CITY" Description="Населенный пункт" PrimaryKey="CityID" DNAttributes="{Name};{CityType}" DisplayName="{1} {0}"><Fields><Attribute Name="CityID" Index="5130001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5130002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5130003" Type="string" Description="Код" CharacterMaximumLength="13"></Attribute><Attribute Name="Okato" Index="5130004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Attribute Name="CityType" Index="5130005" Type="string" Description="Тип населенного пункта" CharacterMaximumLength="10"></Attribute><Attribute Name="ZIPCode" Index="5130006" Type="string" Description="Индекс" CharacterMaximumLength="10"></Attribute><Attribute Name="Status" Index="5130012" Type="int" Description="Статус"></Attribute><Parent Name="Country" Index="5130007" Type="FIES.COUNTRY" Description="Страна"></Parent><Parent Name="Region" Index="5130008" Type="FIES.REGION" Description="Регион"></Parent><Parent Name="Rajon" Index="5130009" Type="FIES.RAJON" Description="Район"></Parent><Child Name="Streets" Index="5130010" Type="FIES.STREET" Description="Улицы" ChildAttribute="City"></Child><Child Name="PoliticalDistricts" Index="5130011" Type="FIES.POLITICAL_DISTRICT" Description="Административные районы города" ChildAttribute="City"></Child></Fields><DbMapping><Table name="T_CITY"><Map Name="CityID" Column="CityID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="CityType" Column="CityType"></Map><Map Name="ZIPCode" Column="ZIPCode"></Map><Map Name="Country" Column="Country"></Map><Map Name="Region" Column="Region"></Map><Map Name="Rajon" Column="Rajon"></Map><Map Name="Status" Column="Status"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='CITY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='COUNTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'COUNTRY',NULL,'Primary SQL Server','Страна',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Страна',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='COUNTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="COUNTRY" Description="Страна" PrimaryKey="CountryID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="CountryID" Index="5100001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5100002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5100003" Type="string" Description="Код" CharacterMaximumLength="13"></Attribute><Attribute Name="Okato" Index="5100004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Attribute Name="FullName" Index="5100005" Type="string" Description="Полное наименование"></Attribute><Attribute Name="Alpha2" Index="5100006" Type="string" Description="Двубуквенный код" Required="1"></Attribute><Attribute Name="Alpha3" Index="5100007" Type="string" Description="Трехбуквенный код"></Attribute></Fields><DbMapping><Table name="T_COUNTRY"><Map Name="CountryID" Column="CountryID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="FullName" Column="FullName"></Map><Map Name="Alpha2" Column="Alpha2"></Map><Map Name="Alpha3" Column="Alpha3"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='COUNTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='DISTRICT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DISTRICT',NULL,'Primary SQL Server','Район города',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Район города',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='DISTRICT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="DISTRICT" Description="Район города" PrimaryKey="DistrictID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="DistrictID" Index="5100001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5140002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5140003" Type="string" Description="Код" CharacterMaximumLength="13"></Attribute><Attribute Name="Okato" Index="5140004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Parent Name="City" Index="5140005" Type="FIES.CITY" Description="Город" Required="1"></Parent></Fields><DbMapping><Table name="T_DISTRICT"><Map Name="DistrictID" Column="DistrictID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="City" Column="City"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='DISTRICT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='PERIOD_DATA')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PERIOD_DATA',NULL,'Primary SQL Server','Данные периода',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Данные периода',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='PERIOD_DATA'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="PERIOD_DATA" Description="Данные периода" PrimaryKey="PeriodDataID"><Fields><Attribute Name="PeriodDataID" Index="7770001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="BeginDate" Index="7770005" Type="date" Description="Дата начала периода" Required="1"></Attribute><Attribute Name="EndDate" Index="7770006" Type="date" Description="Дата окончания периода" Required="1"></Attribute><Attribute Name="CountData" Index="7770007" Type="int" Description="Количество" Required="1"></Attribute><Parent Name="PoliticalDistrict" Index="7770002" Type="FIES.POLITICAL_DISTRICT" Description="Административный район города" Required="1"></Parent><Choice Name="PeriodDataCategory" Index="7770008" Description="Категория периода"><Item Name="Численность" Index="1"></Item></Choice><Choice Name="PeriodDataType" Index="7770009" Description="Тип данных периода"><Item Name="По годам" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_PERIOD_DATA"><Map Name="PeriodDataID" Column="PeriodDataID"></Map><Map Name="PoliticalDistrict" Column="PoliticalDistrict"></Map><Map Name="BeginDate" Column="BeginDate"></Map><Map Name="EndDate" Column="EndDate"></Map><Map Name="CountData" Column="CountData"></Map><Map Name="PeriodDataCategory" Column="PeriodDataCategory"></Map><Map Name="PeriodDataType" Column="PeriodDataType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='PERIOD_DATA'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='POLITICAL_DISTRICT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'POLITICAL_DISTRICT',NULL,'Primary SQL Server','Административный район города',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Административный район города',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='POLITICAL_DISTRICT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="POLITICAL_DISTRICT" Description="Административный район города" PrimaryKey="PoliticalDistrictID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="PoliticalDistrictID" Index="5740001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5740002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5740004" Type="int" Description="Код" Required="1"></Attribute><Parent Name="City" Index="5740003" Type="FIES.CITY" Description="Населенный пункт" Required="1"></Parent></Fields><DbMapping><Table name="T_POLITICAL_DISTRICT"><Map Name="PoliticalDistrictID" Column="PoliticalDistrictID"></Map><Map Name="Name" Column="Name"></Map><Map Name="City" Column="City"></Map><Map Name="Code" Column="Code"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='POLITICAL_DISTRICT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='RAJON')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'RAJON',NULL,'Primary SQL Server','Район',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Район',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='RAJON'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="RAJON" Description="Район" PrimaryKey="RajonID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="RajonID" Index="5120001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5120002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5120003" Type="string" Description="Код" CharacterMaximumLength="13"></Attribute><Attribute Name="Okato" Index="5120004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Parent Name="Region" Index="5120005" Type="FIES.REGION" Description="Регион"></Parent></Fields><DbMapping><Table name="T_RAJON"><Map Name="RajonID" Column="RajonID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="Region" Column="Region"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='RAJON'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='RAJONRT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'RAJONRT',NULL,'Primary SQL Server','Район региона',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Район региона',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='RAJONRT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="RAJONRT" Description="Район региона" PrimaryKey="RajonrtID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="RajonrtID" Index="7330001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="7330002" Type="string" Description="Наименование" CharacterMaximumLength="128" Required="1"></Attribute><Attribute Name="Code" Index="7330003" Type="string" Description="Код" CharacterMaximumLength="4" Required="1"></Attribute></Fields><DbMapping><Table name="T_RAJONRT"><Map Name="RajonrtID" Column="RajonrtID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Code" Column="Code"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='RAJONRT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='REGION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REGION',NULL,'Primary SQL Server','Регион',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Регион',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='REGION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="REGION" Description="Регион" PrimaryKey="RegionID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="RegionID" Index="5110001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5110002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5110003" Type="string" Description="Код" CharacterMaximumLength="13"></Attribute><Attribute Name="Okato" Index="5110004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Attribute Name="RegionType" Index="5110005" Type="string" Description="Тип региона" CharacterMaximumLength="10"></Attribute><Parent Name="Country" Index="5110006" Type="FIES.COUNTRY" Description="Страна" Required="1"></Parent></Fields><DbMapping><Table name="T_REGION"><Map Name="RegionID" Column="RegionID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="RegionType" Column="RegionType"></Map><Map Name="Country" Column="Country"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='REGION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='STREET')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'STREET',NULL,'Primary SQL Server','Улица',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Улица',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='STREET'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="STREET" Description="Улица" PrimaryKey="StreetID" DNAttributes="{Name};{StreetType}" DisplayName="{1} {0}"><Fields><Attribute Name="StreetID" Index="5150001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="5150002" Type="string" Description="Наименование" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="Code" Index="5150003" Type="string" Description="Код" CharacterMaximumLength="17"></Attribute><Attribute Name="Okato" Index="5150004" Type="string" Description="Код ОКАТО" CharacterMaximumLength="11"></Attribute><Attribute Name="StreetType" Index="5150005" Type="string" Description="Тип улицы" CharacterMaximumLength="10"></Attribute><Attribute Name="ZIPCode" Index="5150006" Description="Почтовый индекс" CharacterMaximumLength="10"></Attribute><Parent Name="City" Index="5150007" Type="FIES.CITY" Description="Город"></Parent><Parent Name="District" Index="5150008" Type="FIES.DISTRICT" Description="Район города"></Parent><Parent Name="CreatorUser" Index="5150009" Type="FIES.USERS" Description="Создатель"></Parent></Fields><DbMapping><Table name="T_STREET"><Map Name="StreetID" Column="StreetID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="Okato" Column="Okato"></Map><Map Name="StreetType" Column="StreetType"></Map><Map Name="ZIPCode" Column="ZIPCode"></Map><Map Name="City" Column="City"></Map><Map Name="District" Column="District"></Map><Map Name="CreatorUser" Column="CreatorUser"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='STREET'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTERNAL_PLAN_SUM',NULL,'Primary SQL Server','Внешние данные о планируемых суммах',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Внешние данные о планируемых суммах',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="EXTERNAL_PLAN_SUM" Description="Внешние данные о планируемых суммах" PrimaryKey="ExternalPlanSumID"><Fields><Attribute Name="ExternalPlanSumID" Index="5750001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Mo" Index="5750002" Type="FIES.MO" Description="Медицинская организация" CharacterMaximumLength="6" Required="1"></Parent><Parent Name="PlanPeriod" Index="5750004" Type="FIES.PLAN_PERIOD" Description="Отчётный период" Required="1"></Parent><Parent Name="Subprogramm" Index="5750006" Type="FIES.SUBPROGRAMM" Description="Подпрограмма"></Parent><Child Name="ExternalPlanSumValues" Index="5750005" Type="FIES.EXTERNAL_PLAN_SUM_VALUE" Description="Значения сумм" ChildAttribute="ExternalPlanSum"></Child></Fields><DbMapping><Table name="T_EXTERNAL_PLAN_SUM"><Map Name="ExternalPlanSumID" Column="ExternalPlanSumID"></Map><Map Name="Mo" Column="Mo"></Map><Map Name="PlanPeriod" Column="PlanPeriod"></Map><Map Name="Subprogramm" Column="Subprogramm"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM_VALUE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTERNAL_PLAN_SUM_VALUE',NULL,'Primary SQL Server','Значения сумм внешнего плана',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES'), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значения сумм внешнего плана',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='FIES' and EntName = 'MONTH_VALUES') WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM_VALUE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="EXTERNAL_PLAN_SUM_VALUE" Description="Значения сумм внешнего плана" Inherits="FIES.MONTH_VALUES"><Fields><Parent Name="ExternalPlanSum" Index="5760001" Type="FIES.EXTERNAL_PLAN_SUM" Description="Запись плана" Required="1"></Parent><Parent Name="ParameterGroup" Index="5760002" Type="FIES.PARAMETER_GROUP" Description="Группа параметров"></Parent></Fields><DbMapping><Table name="T_EXTERNAL_PLAN_SUM_VALUE"><Map Name="ExternalPlanSum" Column="ExternalPlanSum"></Map><Map Name="ParameterGroup" Column="ParameterGroup"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='EXTERNAL_PLAN_SUM_VALUE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='FIES' and EntName='RABBIT_SEND_OBJECT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'RABBIT_SEND_OBJECT',NULL,'Primary SQL Server','Отправка объекта в Rabbit',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'FIES')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отправка объекта в Rabbit',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='FIES' and EntName='RABBIT_SEND_OBJECT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="FIES" Name="RABBIT_SEND_OBJECT" Description="Отправка объекта в Rabbit" PrimaryKey="RabbitSendObjectID"><Fields><Attribute Name="RabbitSendObjectID" Index="5180001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="QueueName" Index="5180002" Type="string" Description="Имя очереди" Required="1"></Attribute><Attribute Name="Content" Index="5180004" Type="text" Description="Содержимое" Required="1"></Attribute><Attribute Name="MessageID" Index="5180005" Type="string" Description="Идентификатор сообщения"></Attribute><Attribute Name="Headers" Index="5180007" Type="string" Description="Заголовки"></Attribute><Attribute Name="ContentEncoding" Index="5180008" Type="string" Description="Кодировка"></Attribute><Attribute Name="Type" Index="5180009" Type="string" Description="Тип сообщения" Required="1"></Attribute><Attribute Name="UserID" Index="5180010" Type="string" Description="Идентификатор пользователя"></Attribute><Attribute Name="SendDateTime" Index="5180012" Type="datetime" Description="Дата и время отправки"></Attribute><Attribute Name="CreateDateTime" Index="5180013" Type="datetime" Description="Дата создания объекта на отправку" Required="1"></Attribute><Attribute Name="OwnerID" Index="5180014" Type="string" Description="Идентификатор владельца"></Attribute><Choice Name="State" Index="5180011" Description="Статус" Required="1"><Item Name="Ожидание" Index="0"></Item><Item Name="Отправка" Index="1"></Item><Item Name="Ошибка" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_RABBIT_SEND_OBJECT"><Map Name="RabbitSendObjectID" Column="RabbitSendObjectID"></Map><Map Name="QueueName" Column="QueueName"></Map><Map Name="Content" Column="Content"></Map><Map Name="MessageID" Column="MessageID"></Map><Map Name="Headers" Column="Headers"></Map><Map Name="ContentEncoding" Column="ContentEncoding"></Map><Map Name="Type" Column="Type"></Map><Map Name="UserID" Column="UserID"></Map><Map Name="State" Column="State"></Map><Map Name="SendDateTime" Column="SendDateTime"></Map><Map Name="CreateDateTime" Column="CreateDateTime"></Map><Map Name="OwnerID" Column="OwnerID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='FIES' and EntName='RABBIT_SEND_OBJECT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ACTIVE_FEATURE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ACTIVE_FEATURE',NULL,'Primary SQL Server','Подключенные настройки клиентского модуля',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_FEATURE_SETTINGS'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Подключенные настройки клиентского модуля',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_FEATURE_SETTINGS') WHERE [Schema]='VCLib' and EntName='ACTIVE_FEATURE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ACTIVE_FEATURE" Description="Подключенные настройки клиентского модуля" version="2" UnrestrictedAccess="0" Inherits="VCLib.BASE_FEATURE_SETTINGS"><Fields></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='ACTIVE_FEATURE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ADDITIONAL_ENTITIES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADDITIONAL_ENTITIES',NULL,'Primary SQL Server','Добавленные атрибуты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Добавленные атрибуты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ADDITIONAL_ENTITIES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ADDITIONAL_ENTITIES" Description="Добавленные атрибуты" PrimaryKey="AdditionalEntitiesID"><Fields><Attribute Name="AdditionalEntitiesID" Index="2550001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="EntityID" Index="2550002" Type="int" Description="Идентификатор сущности" Required="1"></Attribute><Attribute Name="EntName" Index="2550003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="EntDesc" Index="2550004" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="ServerName" Index="2550005" Type="string" Description="Имя сервера" Required="1"></Attribute><Attribute Name="BaseEntity" Index="2550006" Type="int" Description="Базовая сущность" Required="1"></Attribute><Attribute Name="ObjectDisplayName" Index="2550007" Type="string" Description="Отображаемое имя"></Attribute><Attribute Name="DNAttributes" Index="2550008" Type="string" Description="Аттрибуты отображения"></Attribute><Parent Name="Schema" Index="2550009" Type="VCLib.SCHEMA" Description="Схема" Required="1"></Parent></Fields><DbMapping><Table name="T_ADDITIONAL_ENTITIES"><Map Name="AdditionalEntitiesID" Column="AdditionalEntitiesID"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="EntName" Column="EntName"></Map><Map Name="EntDesc" Column="EntDesc"></Map><Map Name="ServerName" Column="ServerName"></Map><Map Name="BaseEntity" Column="BaseEntity"></Map><Map Name="ObjectDisplayName" Column="DisplayName"></Map><Map Name="DNAttributes" Column="DNAttributes"></Map><Map Name="Schema" Column="Schema"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ADDITIONAL_ENTITIES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='BAE_ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BAE_ROLES',NULL,'Primary SQL Server','Распределение прав на процессы по ролям',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Распределение прав на процессы по ролям',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='BAE_ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="BAE_ROLES" Description="Распределение прав на процессы по ролям" version="2" PrimaryKey="EntryRoleID" DNAttributes="{RoleID/RoleName};{EntryID/EntryDescription}" DisplayName="{0} &lt;=&gt; {1}" UnrestrictedAccess="1"><Fields><Attribute Name="EntryRoleID" Index="250001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="RoleID" Index="250002" Type="VCLib.ROLES" Description="Роль"></Parent><Parent Name="EntryID" Index="250003" Type="VCLib.BASE_ACCESS_ENTRY" Description="Право доступа"></Parent></Fields><DbMapping><Table name="T_BAE_ROLES"><Map Name="EntryRoleID" Column="EntryRoleID"></Map><Map Name="RoleID" Column="RoleID"></Map><Map Name="EntryID" Column="EntryID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='BAE_ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='BASE_ACCESS_ENTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BASE_ACCESS_ENTRY',NULL,'Primary SQL Server','Право доступа',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право доступа',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='BASE_ACCESS_ENTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="BASE_ACCESS_ENTRY" Description="Право доступа" version="2" PrimaryKey="EntryID" DNAttributes="{EntryDescription}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="EntryID" Index="240001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="EntryDescription" Index="240002" Type="string" Description="Описание"></Attribute><Child Name="ROLES" Index="240003" Type="VCLib.BAE_ROLES" Description="Роли" ChildAttribute="EntryID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_BASE_ACCESS_ENTRY"><Map Name="EntryID" Column="EntryID"></Map><Map Name="EntryDescription" Column="EntryDescription"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='BASE_ACCESS_ENTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='BASE_FEATURE_SETTINGS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BASE_FEATURE_SETTINGS',NULL,'Primary SQL Server','Базовые настройки клиентского модуля',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Базовые настройки клиентского модуля',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='BASE_FEATURE_SETTINGS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="BASE_FEATURE_SETTINGS" Description="Базовые настройки клиентского модуля" version="2" PrimaryKey="BaseFeatureSettingsID" UnrestrictedAccess="0"><Fields><Attribute Name="BaseFeatureSettingsID" Index="2010001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="ClientModuleFeature" Index="2010002" Type="VCLib.CLIENT_MODULE_FEATURE" Description="Настройки клиентского модуля" Required="1"></Parent><Parent Name="RoleClientModules" Index="2010003" Type="VCLib.ROLE_CLIENT_MODULES" Description="Сущность-связка между ROLES и CLIENT_MODULES" Required="1"></Parent></Fields><DbMapping><Table name="T_BASE_FEATURE_SETTINGS"><Map Name="BaseFeatureSettingsID" Column="BaseFeatureSettingsID"></Map><Map Name="ClientModuleFeature" Column="ClientModuleFeature"></Map><Map Name="RoleClientModules" Column="RoleClientModules"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='BASE_FEATURE_SETTINGS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='BASE_USERS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BASE_USERS',NULL,'Primary SQL Server','Базовая сущность для пользователей системы.',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Базовая сущность для пользователей системы.',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='BASE_USERS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="BASE_USERS" Description="Базовая сущность для пользователей системы." version="2" PrimaryKey="UserID" DNAttributes="{UserName}" DisplayName="{0}" UnrestrictedAccess="0"><Customs><Custom Name="uniqueness" Value="(50002)"></Custom><Custom Name="NotDisplayedColumns" Value="Password;Salt"></Custom><Custom Name="NotDisplayedInFilter" Value="Password;Salt"></Custom></Customs><Fields><Attribute Name="Password" Index="200002" Type="string" Description="Пароль"></Attribute><Attribute Name="Salt" Index="200003" Type="string" Description="Соль"></Attribute><Attribute Name="UserParameters" Index="200004" Type="binary" Description="Таблица параметров пользователя"></Attribute><Attribute Name="LastPasswordChangeDate" Index="200005" Type="datetime" Description="Дата и время последней смены пароля" DefaultFormat="dd.MM.yyyy HH:mm"></Attribute><Attribute Name="UserID" Index="50001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Login" Index="50002" Type="string" Description="Логин" Required="1"></Attribute><Attribute Name="UserName" Index="50004" Type="string" Description="Полное имя" Required="1"></Attribute><Attribute Name="Active" Index="50006" Type="bool" Description="Активный"></Attribute><Parent Name="DivisionID" Index="50017" Type="VCLib.DIVISIONS" Description="Подразделение" Required="1"></Parent><Child Name="USER_ROLES" Index="50009" Type="VCLib.USERS_ROLES" Description="Роли" ChildAttribute="UserID" RemoveAction="0"></Child><Child Name="USER_SEARCH_USER" Index="50015" Type="VCLib.USER_SEARCHES" Description="Сохраненные фильтры" ChildAttribute="UserID" RemoveAction="0"></Child><Child Name="USER_CONTEXT_USER" Index="50016" Type="VCLib.USER_CONTEXTS" Description="Пользовательские контексты" ChildAttribute="UserID" RemoveAction="0"></Child><Choice Name="Flags" Index="50005" Description="Флаги" Required="1" IsFlag="1"><Item Name="Активный" Index="1"></Item><Item Name="Необходимо сменить пароль" Index="2"></Item><Item Name="Право на подключение с других серверов" Index="4"></Item></Choice><Choice Name="AuthenticationType" Index="50018" Description="Проверка подлинности" Required="1"><Item Name="Системная аутентификация" Index="0"></Item><Item Name="Windows аутентификация" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_USERS"><Map Name="UserID" Column="UserID"></Map><Map Name="Login" Column="Login"></Map><Map Name="UserName" Column="UserName"></Map><Map Name="DivisionID" Column="DivisionID"></Map><Map Name="Password" Column="Password"></Map><Map Name="Salt" Column="Salt"></Map><Map Name="AuthenticationType" Column="AuthenticationType"></Map><Map Name="UserParameters" Column="UserParameters"></Map><Map Name="Flags" Column="Flags"></Map><Map Name="LastPasswordChangeDate" Column="LastPasswordChangeDate"></Map></Table><Lexem><Map Name="Active"><lx:MathOperator sign="&amp;" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="50005" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[1]]></lx:ConstOperand></lx:MathOperator></Map></Lexem></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='BASE_USERS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CHANGESET')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CHANGESET',NULL,'Primary SQL Server','Пакет изменений',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Пакет изменений',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CHANGESET'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CHANGESET" Description="Пакет изменений" version="2" PrimaryKey="ID" UnrestrictedAccess="1"><Fields><Attribute Name="ID" Index="620001" Type="int" Description="Идентификатор"></Attribute><Attribute Name="Timestamp" Index="620002" Type="datetime" Description="Дата и время" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Required="1"></Attribute><Attribute Name="Context" Index="620003" Type="string" Description="Контекст"></Attribute><Parent Name="User" Index="620004" Type="VCLib.BASE_USERS" Description="Пользователь" Required="1"></Parent></Fields><DbMapping><Table name="T_CHANGESETS"><Map Name="ID" Column="ID"></Map><Map Name="Timestamp" Column="Timestamp"></Map><Map Name="Context" Column="Context"></Map><Map Name="User" Column="UserId"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='CHANGESET'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CLIENT_MODULE_FEATURE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CLIENT_MODULE_FEATURE',NULL,'Primary SQL Server','Настройки клиентского модуля',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройки клиентского модуля',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CLIENT_MODULE_FEATURE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CLIENT_MODULE_FEATURE" Description="Настройки клиентского модуля" version="2" PrimaryKey="ClientModuleFeatureID" DNAttributes="{Description}" DisplayName="{0}" UnrestrictedAccess="0"><Fields><Attribute Name="ClientModuleFeatureID" Index="2000001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="2000002" Type="string" Description="Наименование" CharacterMaximumLength="100" Required="1"></Attribute><Attribute Name="Description" Index="2000003" Type="string" Description="Описание" CharacterMaximumLength="255" Required="1"></Attribute><Parent Name="ClientModules" Index="2000004" Type="VCLib.CLIENT_MODULES" Description="Модуль" Required="1"></Parent><Parent Name="EntityIndex" Index="2000005" Type="VCLib.ENTITIES" Description="Сущность с настройками" Required="1"></Parent></Fields><DbMapping><Table name="T_CLIENT_MODULE_FEATURE"><Map Name="ClientModuleFeatureID" Column="ClientModuleFeatureID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ClientModules" Column="ClientModules"></Map><Map Name="EntityIndex" Column="EntityIndex"></Map><Map Name="Description" Column="Description"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='CLIENT_MODULE_FEATURE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CLIENT_MODULES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CLIENT_MODULES',NULL,'Primary SQL Server','Модули',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Модули',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CLIENT_MODULES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CLIENT_MODULES" Description="Модули" version="2" PrimaryKey="ClientModuleID" DNAttributes="{ModuleDescription}" DisplayName="CLIENT_MODULES:{0}"><Fields><Attribute Name="ClientModuleID" Index="220001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="ModuleType" Index="220002" Type="string" Description="Тип модуля" Required="1"></Attribute><Attribute Name="ModuleDescription" Index="220003" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="Priority" Index="220005" Type="int" Description="Приоритет"></Attribute><Child Name="MODULE_ROLES" Index="220004" Type="VCLib.ROLE_CLIENT_MODULES" Description="Роли" ChildAttribute="ClientModuleID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_CLIENT_MODULES"><Map Name="ClientModuleID" Column="ClientModuleID"></Map><Map Name="ModuleType" Column="ModuleType"></Map><Map Name="ModuleDescription" Column="ModuleDescription"></Map><Map Name="Priority" Column="Priority"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='CLIENT_MODULES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CUSTOM_PROCESS_HANDLER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CUSTOM_PROCESS_HANDLER',NULL,'Primary SQL Server','Обработчик процесса',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Обработчик процесса',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CUSTOM_PROCESS_HANDLER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CUSTOM_PROCESS_HANDLER" Description="Обработчик процесса" PrimaryKey="CustomProcessHandlerID" DNAttributes="{ProcessName}" DisplayName="Обработчик процесса {0}"><Fields><Attribute Name="CustomProcessHandlerID" Index="530001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="ProcessName" Index="530002" Type="string" Description="Имя процесса" Required="1"></Attribute><Attribute Name="ObjectName" Index="530003" Type="string" Description="Тип объекта"></Attribute><Attribute Name="PrepareLexem" Index="530004" Type="text" Description="Prepare"></Attribute><Attribute Name="ExecuteLexem" Index="530005" Type="text" Description="Execute"></Attribute><Attribute Name="PostExecuteLexem" Index="530006" Type="text" Description="PostExecute"></Attribute></Fields><DbMapping><Table name="T_PROCESS_HANDLER_CUSTOM"><Map Name="CustomProcessHandlerID" Column="CustomProcessHandlerID"></Map><Map Name="ProcessName" Column="ProcessName"></Map><Map Name="ObjectName" Column="ObjectName"></Map><Map Name="PrepareLexem" Column="PrepareLexem"></Map><Map Name="ExecuteLexem" Column="ExecuteLexem"></Map><Map Name="PostExecuteLexem" Column="PostExecuteLexem"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='CUSTOM_PROCESS_HANDLER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DATAFORM_EXTENSION',NULL,'Primary SQL Server','Расширение функционала формы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Расширение функционала формы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DATAFORM_EXTENSION" Description="Расширение функционала формы" PrimaryKey="DataformExtensionID"><Fields><Attribute Name="DataformExtensionID" Index="2520001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="FormContext" Index="2520003" Type="string" Description="Контекст формы"></Attribute><Attribute Name="TabPageName" Index="2520006" Type="string" Description="Наименование вкладки" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="TabControlName" Index="2520007" Type="string" Description="Контейнер вкладки" CharacterMaximumLength="255"></Attribute><Attribute Name="ExtensionOrder" Index="2520008" Type="int" Description="Порядоковый номер" Required="1"></Attribute><Parent Name="Entities" Index="2520002" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="DataformExtensionRoles" Index="2520004" Type="VCLib.DATAFORM_EXTENSION_ROLE" Description="Роли" ChildAttribute="DataformExtension"></Child><Child Name="DataformExtensionAddattributes" Index="2520005" Type="VCLib.DATAFORM_EXTENSION_ADDATTRIBUTE" Description="Добавленные атрибуты" ChildAttribute="DataformExtension"></Child></Fields><DbMapping><Table name="T_DATAFORM_EXTENSION"><Map Name="DataformExtensionID" Column="DataformExtensionID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="FormContext" Column="FormContext"></Map><Map Name="TabPageName" Column="TabPageName"></Map><Map Name="TabControlName" Column="TabControlName"></Map><Map Name="ExtensionOrder" Column="ExtensionOrder"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ADDATTRIBUTE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DATAFORM_EXTENSION_ADDATTRIBUTE',NULL,'Primary SQL Server','Добавленный атрибут на форму',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Добавленный атрибут на форму',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ADDATTRIBUTE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DATAFORM_EXTENSION_ADDATTRIBUTE" Description="Добавленный атрибут на форму" PrimaryKey="DataformExtensionAddattributeID"><Fields><Attribute Name="DataformExtensionAddattributeID" Index="2540001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="AttributePath" Index="2540003" Type="string" Description="Путь до атрибута" CharacterMaximumLength="1024" Required="1"></Attribute><Attribute Name="AttributeDescr" Index="2540004" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="Priority" Index="2540006" Type="int" Description="Приоритет" Required="1"></Attribute><Parent Name="DataformExtension" Index="2540002" Type="VCLib.DATAFORM_EXTENSION" Description="Расширение функционала формы" Required="1"></Parent><Choice Name="AttributeEdit" Index="2540005" Description="Разрешено редактирование" Required="1"><Item Name="Не разрешено" Index="0"></Item><Item Name="По умолчанию" Index="1"></Item><Item Name="Разрешено" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_DATAFORM_EXTENSION_ADDATTRIBUTE"><Map Name="DataformExtensionAddattributeID" Column="DataformExtensionAddattributeID"></Map><Map Name="DataformExtension" Column="DataformExtension"></Map><Map Name="AttributePath" Column="AttributePath"></Map><Map Name="AttributeDescr" Column="AttributeDescr"></Map><Map Name="AttributeEdit" Column="AttributeEdit"></Map><Map Name="Priority" Column="Priority"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ADDATTRIBUTE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ROLE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DATAFORM_EXTENSION_ROLE',NULL,'Primary SQL Server','Роли с доступом к расширению формы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Роли с доступом к расширению формы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ROLE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DATAFORM_EXTENSION_ROLE" Description="Роли с доступом к расширению формы" PrimaryKey="DataformExtensionRoleID"><Fields><Attribute Name="DataformExtensionRoleID" Index="2530001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Roles" Index="2530002" Type="VCLib.ROLES" Description="Роль пользователя в системе" Required="1"></Parent><Parent Name="DataformExtension" Index="2530003" Type="VCLib.DATAFORM_EXTENSION" Description="Расширение функционала формы" Required="1"></Parent></Fields><DbMapping><Table name="T_DATAFORM_EXTENSION_ROLE"><Map Name="DataformExtensionRoleID" Column="DataformExtensionRoleID"></Map><Map Name="Roles" Column="Roles"></Map><Map Name="DataformExtension" Column="DataformExtension"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DATAFORM_EXTENSION_ROLE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DATAFORM_TEMPLATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DATAFORM_TEMPLATE',NULL,'Primary SQL Server','Шаблон для форм',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон для форм',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DATAFORM_TEMPLATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DATAFORM_TEMPLATE" Description="Шаблон для форм" PrimaryKey="DataformTemplateID"><Fields><Attribute Name="DataformTemplateID" Index="3000001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3000002" Type="string" Description="Наименование" CharacterMaximumLength="128" Required="1"></Attribute><Attribute Name="Category" Index="3000003" Type="string" Description="Категория" CharacterMaximumLength="128"></Attribute><Attribute Name="TemplateData" Index="3000004" Type="text" Description="Значение шаблона"></Attribute><Attribute Name="FormContext" Index="3000006" Type="string" Description="Контекст формы" CharacterMaximumLength="64"></Attribute><Parent Name="Users" Index="3000005" Type="VCLib.BASE_USERS" Description="Пользователи системы"></Parent><Parent Name="Entities" Index="3000007" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent></Fields><DbMapping><Table name="T_DATAFORM_TEMPLATE"><Map Name="DataformTemplateID" Column="DataformTemplateID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Category" Column="Category"></Map><Map Name="TemplateData" Column="TemplateData"></Map><Map Name="Users" Column="Users"></Map><Map Name="FormContext" Column="FormContext"></Map><Map Name="Entities" Column="Entities"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DATAFORM_TEMPLATE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DbServers')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DbServers',NULL,'Primary SQL Server','Серверы баз данных',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Серверы баз данных',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DbServers'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DbServers" Description="Серверы баз данных" PrimaryKey="DbServerId"><Fields><Attribute Name="DbServerId" Index="950001" Type="int" Description="Идентификатор" Required="1"></Attribute><Attribute Name="Name" Index="950002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="IsLocal" Index="950003" Type="bool" Description="Текущий сервер" Required="1"></Attribute></Fields><DbMapping><Table name="T_DbServers"><Map Name="DbServerId" Column="DbServerId"></Map><Map Name="Name" Column="Name"></Map><Map Name="IsLocal" Column="IsLocal"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DbServers'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DIVISIONS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DIVISIONS',NULL,'Primary SQL Server','Подразделение',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Подразделение',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DIVISIONS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DIVISIONS" Description="Подразделение" version="2" PrimaryKey="DivisionID" DNAttributes="{Name}" DisplayName="{0}" IsTree="1"><Fields><Attribute Name="DivisionID" Index="330001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="330002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="FullName" Index="330003" Type="string" Description="Полное наименование" Required="1"></Attribute><Attribute Name="LeftIndex" Index="330004" Type="int" Description="Левый индекс"></Attribute><Attribute Name="RightIndex" Index="330005" Type="int" Description="Правый индекс"></Attribute><Attribute Name="TreeLevel" Index="330006" Type="int" Description="Уровень дерева"></Attribute><Parent Name="ParentID" Index="330007" Type="VCLib.DIVISIONS" Description="Родительская категория"></Parent><Child Name="Children" Index="330008" Type="VCLib.DIVISIONS" Description="Дочерние категории" ChildAttribute="ParentID"></Child></Fields><DbMapping><Table name="T_DIVISIONS"><Map Name="DivisionID" Column="DivisionID"></Map><Map Name="Name" Column="Name"></Map><Map Name="FullName" Column="FullName"></Map><Map Name="LeftIndex" Column="LeftIndex"></Map><Map Name="RightIndex" Column="RightIndex"></Map><Map Name="TreeLevel" Column="TreeLevel"></Map><Map Name="ParentID" Column="ParentID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DIVISIONS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENTITIES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENTITIES',NULL,'Primary SQL Server','Сущности метаданных',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сущности метаданных',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ENTITIES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENTITIES" Description="Сущности метаданных" version="2" PrimaryKey="EntityID" DNAttributes="{EntName}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="EntityID" Index="10001" Type="int" Description="Идентификатор"></Attribute><Attribute Name="EntName" Index="10002" Type="string" Description="Наименование"></Attribute><Attribute Name="EntDesc" Index="10003" Type="string" Description="Описание сущности данных"></Attribute><Attribute Name="ServerName" Index="10004" Type="string" Description="Сервер БД"></Attribute><Attribute Name="XML" Index="10005" Type="text" Description="XML-описание сущности"></Attribute><Attribute Name="NeedHistory" Index="10006" Type="bool" Description="Необходимость ведения истории изменений"></Attribute><Attribute Name="ObjectDisplayName" Index="10012" Type="string" Description="Отображаемое имя"></Attribute><Attribute Name="DNAttributes" Index="10013" Type="string" Description="Аттрибуты отображения"></Attribute><Parent Name="BaseEntity" Index="10011" Type="VCLib.ENTITIES" Description="Базовая сущность"></Parent><Parent Name="Schema" Index="10014" Type="VCLib.SCHEMA" Description="Схема" Required="1"></Parent><Child Name="USER_SEARCH_ENTITY" Index="10008" Type="VCLib.USER_SEARCHES" Description="Сохраненные фильтры" ChildAttribute="EntityID" RemoveAction="0"></Child><Child Name="HiddenAttributes" Index="10009" Type="VCLib.HIDDEN_ATTRIBUTE" Description="Скрытые аттрибуты" ChildAttribute="Entities"></Child><Child Name="EntityAttributes" Index="10010" Type="VCLib.ENTITY_ATTRIBUTES" Description="Добавленные аттрибуты" ChildAttribute="EntityID"></Child></Fields><DbMapping><Table name="T_ENTITIES"><Map Name="EntityID" Column="EntityID" IsStored="0"></Map><Map Name="EntName" Column="EntName" IsStored="0"></Map><Map Name="EntDesc" Column="EntDesc" IsStored="0"></Map><Map Name="ServerName" Column="ServerName" IsStored="0"></Map><Map Name="XML" Column="XML" IsStored="0"></Map><Map Name="NeedHistory" Column="NeedHistory" IsStored="0"></Map><Map Name="BaseEntity" Column="BaseEntity" IsStored="0"></Map><Map Name="Schema" Column="Schema"></Map></Table><Table name="T_ADDITIONAL_ENTITIES"><Map Name="ObjectDisplayName" Column="DisplayName"></Map><Map Name="DNAttributes" Column="DNAttributes"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENTITIES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENTITIES_ATTRIBUTES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENTITIES_ATTRIBUTES',NULL,'Primary SQL Server','Добавленный аттрибут',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Добавленный аттрибут',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ENTITIES_ATTRIBUTES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENTITIES_ATTRIBUTES" Description="Добавленный аттрибут" PrimaryKey="EntitiesAttributesId"><Fields><Attribute Name="EntitiesAttributesId" Index="440001" Type="string" Description="Идентификатор"></Attribute><Attribute Name="AttrIndex" Index="440002" Type="int" Description="Индекс атрибута" Required="1"></Attribute><Attribute Name="Name" Index="440003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="AttrDescription" Index="440004" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="SystemType" Index="440005" Type="string" Description="Системный тип"></Attribute><Attribute Name="MaxLength" Index="440006" Type="int" Description="Количество символов"></Attribute><Attribute Name="Precision" Index="440007" Type="int" Description="Точность"></Attribute><Attribute Name="Scale" Index="440008" Type="int" Description="Масштаб"></Attribute><Attribute Name="DefaultFormat" Index="440009" Type="string" Description="Формат по умолчанию"></Attribute><Attribute Name="IsCalculated" Index="440010" Type="bool" Description="Вычислимое" Required="1"></Attribute><Attribute Name="IsFlag" Index="440011" Type="bool" Description="Битовый чойс" Required="1"></Attribute><Attribute Name="IsRequired" Index="440012" Type="bool" Description="Обязательное поле" Required="1"></Attribute><Attribute Name="MappingName" Index="440013" Type="string" Description="Маппирование на"></Attribute><Attribute Name="IsSave" Index="440014" Type="bool" Description="Сохранять связанный объект" Required="1"></Attribute><Attribute Name="LinkAttributeName" Index="440015" Type="string" Description="Имя атрибута связки"></Attribute><Attribute Name="ChoiceAttributeData" Index="440016" Type="string" Description="Данные чойс атрибута" CharacterMaximumLength="8000"></Attribute><Attribute Name="IsStored" Index="440017" Type="bool" Description="Сохранять аттрибут" Required="1"></Attribute><Attribute Name="AttrLexem" Index="440018" Type="text" Description="Лексема"></Attribute><Attribute Name="PathsAttributes" Index="440019" Type="text" Description="Пути до коллекции"></Attribute><Attribute Name="IsCashed" Index="440020" Type="bool" Description="Кеширование значения" Required="1"></Attribute><Parent Name="EntityID" Index="440021" Type="VCLib.ENTITIES" Description="Сущность" Required="1"></Parent><Choice Name="AttributeType" Index="440022" Description="Тип атрибута" Required="1"><Item Name="PrimaryKey" Index="-1"></Item><Item Name="Attribute" Index="0"></Item><Item Name="Parent" Index="1"></Item><Item Name="Child" Index="2"></Item><Item Name="Link" Index="3"></Item><Item Name="Choice" Index="4"></Item></Choice><Choice Name="MappingType" Index="440023" Description="Маппирование"><Item Name="Не маппировано" Index="0"></Item><Item Name="Колонка" Index="1"></Item><Item Name="Функция" Index="2"></Item><Item Name="Таблица" Index="3"></Item><Item Name="Лексема" Index="4"></Item></Choice></Fields><DbMapping><Table name="T_ENTITIES_ATTRIBUTES"><Map Name="EntitiesAttributesId" Column="EntitiesAttributesId"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="AttrIndex" Column="Index"></Map><Map Name="AttributeType" Column="AttributeType"></Map><Map Name="Name" Column="Name"></Map><Map Name="AttrDescription" Column="Description"></Map><Map Name="SystemType" Column="SystemType"></Map><Map Name="MaxLength" Column="MaxLength"></Map><Map Name="Precision" Column="Precision"></Map><Map Name="Scale" Column="Scale"></Map><Map Name="DefaultFormat" Column="DefaultFormat"></Map><Map Name="IsCalculated" Column="IsCalculated"></Map><Map Name="IsFlag" Column="IsFlag"></Map><Map Name="IsRequired" Column="IsRequired"></Map><Map Name="MappingType" Column="MappingType"></Map><Map Name="MappingName" Column="MappingName"></Map><Map Name="IsSave" Column="Save"></Map><Map Name="LinkAttributeName" Column="LinkAttributeName"></Map><Map Name="ChoiceAttributeData" Column="ChoiceAttributeData"></Map><Map Name="IsStored" Column="IsStored"></Map><Map Name="AttrLexem" Column="AttrLexem"></Map><Map Name="PathsAttributes" Column="PathsAttributes"></Map><Map Name="IsCashed" Column="IsCashed"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENTITIES_ATTRIBUTES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENTITY_ACCESS_ENTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENTITY_ACCESS_ENTRY',NULL,'Primary SQL Server','Право доступа к сущности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право доступа к сущности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY') WHERE [Schema]='VCLib' and EntName='ENTITY_ACCESS_ENTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENTITY_ACCESS_ENTRY" Description="Право доступа к сущности" version="2" PrimaryKey="EntryID" UnrestrictedAccess="1" Inherits="VCLib.BASE_ACCESS_ENTRY"><Fields><Attribute Name="Access" Index="290001" Type="int" Description="Доступ" Required="1"></Attribute><Attribute Name="LexemContent" Index="290002" Type="string" Description="Лексема"></Attribute><Parent Name="EntityID" Index="290003" Type="VCLib.ENTITIES" Description="Сущность" Required="0" Save="0"></Parent></Fields><DbMapping><Table name="T_ENTITY_ACCESS_ENTRY"><Map Name="Access" Column="AccessType"></Map><Map Name="LexemContent" Column="LexemContent"></Map><Map Name="EntityID" Column="EntityID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENTITY_ACCESS_ENTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTE_ACCESS_ENTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENTITY_ATTRIBUTE_ACCESS_ENTRY',NULL,'Primary SQL Server','Право доступа к атрибутам сущности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право доступа к атрибутам сущности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY') WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTE_ACCESS_ENTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENTITY_ATTRIBUTE_ACCESS_ENTRY" Description="Право доступа к атрибутам сущности" version="2" PrimaryKey="EntryID" UnrestrictedAccess="1" Inherits="VCLib.BASE_ACCESS_ENTRY"><Customs><Custom Name="NotDisplayedInFilter" Value="Attributes;LexemContent"></Custom></Customs><Fields><Attribute Name="Access" Index="300001" Type="int" Description="Доступ" Required="1"></Attribute><Attribute Name="Attributes" Index="300002" Type="string" Description="Атрибуты" Required="1"></Attribute><Attribute Name="LexemContent" Index="300003" Type="string" Description="Лексема"></Attribute><Parent Name="EntityID" Index="300004" Type="VCLib.ENTITIES" Description="Сущность" Required="1" Save="0"></Parent></Fields><DbMapping><Table name="T_ENT_ATTR_ACCESS_ENTRY"><Map Name="Access" Column="AccessType"></Map><Map Name="Attributes" Column="Attributes"></Map><Map Name="LexemContent" Column="LexemContent"></Map><Map Name="EntityID" Column="EntityID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTE_ACCESS_ENTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENTITY_ATTRIBUTES',NULL,'Primary SQL Server','Добавленный аттрибут',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Добавленный аттрибут',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENTITY_ATTRIBUTES" Description="Добавленный аттрибут" PrimaryKey="EntityAttributesID"><Fields><Attribute Name="EntityAttributesID" Index="2510001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="AttrIndex" Index="2510003" Type="int" Description="Индекс атрибута" Required="1"></Attribute><Attribute Name="Name" Index="2510005" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="AttrDescription" Index="2510006" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="SystemType" Index="2510007" Type="string" Description="Системный тип" Required="1"></Attribute><Attribute Name="MaxLength" Index="2510008" Type="int" Description="Количество символов"></Attribute><Attribute Name="Precision" Index="2510009" Type="int" Description="Точность"></Attribute><Attribute Name="Scale" Index="2510010" Type="int" Description="Масштаб"></Attribute><Attribute Name="DefaultFormat" Index="2510011" Type="string" Description="Формат по умолчанию"></Attribute><Attribute Name="IsCalculated" Index="2510012" Type="bool" Description="Вычислимое" Required="1"></Attribute><Attribute Name="IsFlag" Index="2510013" Type="bool" Description="Битовый чойс" Required="1"></Attribute><Attribute Name="IsRequired" Index="2510014" Type="bool" Description="Обязательное поле" Required="1"></Attribute><Attribute Name="MappingName" Index="2510016" Type="string" Description="Маппирование на"></Attribute><Attribute Name="IsSave" Index="2510017" Type="bool" Description="Сохранять связанный объект" Required="1"></Attribute><Attribute Name="LinkAttributeName" Index="2510018" Type="string" Description="Имя атрибута связки"></Attribute><Attribute Name="ChoiceAttributeData" Index="2510019" Type="string" Description="Данные чойс атрибута" CharacterMaximumLength="8000"></Attribute><Attribute Name="IsStored" Index="2510020" Type="bool" Description="Сохранять аттрибут" Required="1"></Attribute><Attribute Name="AttrLexem" Index="2510021" Type="text" Description="Лексема"></Attribute><Attribute Name="PathsAttributes" Index="2510022" Type="text" Description="Пути до коллекции"></Attribute><Attribute Name="IsCashed" Index="2510023" Type="bool" Description="Кеширование значения" Required="1"></Attribute><Parent Name="EntityID" Index="2510002" Type="VCLib.ENTITIES" Description="Сущность" Required="1"></Parent><Choice Name="AttributeType" Index="2510004" Description="Тип атрибута" Required="1"><Item Name="Attribute" Index="0"></Item><Item Name="Parent" Index="1"></Item><Item Name="Child" Index="2"></Item><Item Name="Link" Index="3"></Item><Item Name="Choice" Index="4"></Item></Choice><Choice Name="MappingType" Index="2510015" Description="Маппирование"><Item Name="Не маппировано" Index="0"></Item><Item Name="Колонка" Index="1"></Item><Item Name="Функция" Index="2"></Item><Item Name="Таблица" Index="3"></Item><Item Name="Лексема" Index="4"></Item></Choice></Fields><DbMapping><Table name="T_ENTITY_ATTRIBUTES"><Map Name="EntityAttributesID" Column="EntityAttributesID"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="AttrIndex" Column="Index"></Map><Map Name="AttributeType" Column="AttributeType"></Map><Map Name="Name" Column="Name"></Map><Map Name="AttrDescription" Column="Description"></Map><Map Name="SystemType" Column="SystemType"></Map><Map Name="MaxLength" Column="MaxLength"></Map><Map Name="Precision" Column="Precision"></Map><Map Name="Scale" Column="Scale"></Map><Map Name="DefaultFormat" Column="DefaultFormat"></Map><Map Name="IsCalculated" Column="IsCalculated"></Map><Map Name="IsFlag" Column="IsFlag"></Map><Map Name="IsRequired" Column="IsRequired"></Map><Map Name="MappingType" Column="MappingType"></Map><Map Name="MappingName" Column="MappingName"></Map><Map Name="IsSave" Column="Save"></Map><Map Name="LinkAttributeName" Column="LinkAttributeName"></Map><Map Name="ChoiceAttributeData" Column="ChoiceAttributeData"></Map><Map Name="IsStored" Column="IsStored"></Map><Map Name="AttrLexem" Column="AttrLexem"></Map><Map Name="PathsAttributes" Column="PathsAttributes"></Map><Map Name="IsCashed" Column="IsCashed"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENTITY_ATTRIBUTES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENUM_ACCESS_ENTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENUM_ACCESS_ENTRY',NULL,'Primary SQL Server','Право доступа к перечислению',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право доступа к перечислению',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY') WHERE [Schema]='VCLib' and EntName='ENUM_ACCESS_ENTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENUM_ACCESS_ENTRY" Description="Право доступа к перечислению" version="2" PrimaryKey="EntryID" UnrestrictedAccess="1" Inherits="VCLib.BASE_ACCESS_ENTRY"><Fields><Attribute Name="Enabled" Index="270001" Type="bool" Description="Доступ разрешен" Required="1"></Attribute><Parent Name="EnumTypeID" Index="270002" Type="VCLib.ENUM_TYPES" Description="Тип перечисления" Required="1" Save="0"></Parent></Fields><DbMapping><Table name="T_ENUM_ACCESS_ENTRY"><Map Name="Enabled" Column="Enabled"></Map><Map Name="EnumTypeID" Column="EnumTypeID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENUM_ACCESS_ENTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENUM_TYPES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENUM_TYPES',NULL,'Primary SQL Server','Типы перечисляемых значений',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Типы перечисляемых значений',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ENUM_TYPES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENUM_TYPES" Description="Типы перечисляемых значений" version="2" PrimaryKey="EnumTypeID" DNAttributes="{Description}" DisplayName="{0}" UnrestrictedAccess="0"><Fields><Attribute Name="EnumTypeID" Index="60001" Type="int" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="60002" Type="string" Description="Наименование"></Attribute><Attribute Name="Description" Index="60003" Type="string" Description="Описание" Required="1"></Attribute><Child Name="TYPES_OF_ENUM" Index="60004" Type="VCLib.ENUMS" Description="Значения" ChildAttribute="EnumTypeID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_ENUM_TYPES"><Map Name="EnumTypeID" Column="EnumTypeID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Description" Column="Description"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENUM_TYPES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ENUMS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ENUMS',NULL,'Primary SQL Server','Списки возможных значений атрибутов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Списки возможных значений атрибутов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ENUMS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ENUMS" Description="Списки возможных значений атрибутов" version="2" PrimaryKey="EnumID" DNAttributes="{Name}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="EnumID" Index="70001" Type="int" Description="Идентификатор"></Attribute><Attribute Name="Code" Index="70002" Type="int" Description="Код" Required="1"></Attribute><Attribute Name="Name" Index="70003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="ShortName" Index="70004" Type="string" Description="Короткое наименование"></Attribute><Attribute Name="Active" Index="70005" Type="boolean" Description="Активен"></Attribute><Attribute Name="Alias" Index="70006" Type="string" Description="Вспомогательный alias"></Attribute><Parent Name="EnumTypeID" Index="70007" Type="VCLib.ENUM_TYPES" Description="Тип значения"></Parent></Fields><DbMapping><Table name="T_ENUMS"><Map Name="EnumID" Column="EnumID"></Map><Map Name="Code" Column="Code"></Map><Map Name="Name" Column="Name"></Map><Map Name="ShortName" Column="ShortName"></Map><Map Name="Active" Column="Active"></Map><Map Name="Alias" Column="Alias"></Map><Map Name="EnumTypeID" Column="EnumTypeID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ENUMS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_TEMPLATE',NULL,'Primary SQL Server','Шаблон пользовательских списков',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон пользовательских списков',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_TEMPLATE" Description="Шаблон пользовательских списков" Inherits="VCLib.FILES"><Fields><Attribute Name="ReportFileParameters" Index="980003" Type="text" Description="Параметры шаблона"></Attribute><Attribute Name="OutputName" Index="980004" Type="string" Description="Имя выходного файла" CharacterMaximumLength="1000"></Attribute><Parent Name="ReportFileFormat" Index="980001" Type="VCLib.ReportFileFormat" Description="Формат отчета" Required="1"></Parent><Parent Name="ExtraUiCommand" Index="980002" Type="VCLib.EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" Required="1"></Parent><Parent Name="ReportFormType" Index="980007" Type="VCLib.ENUMS" Description="Вид отчета" EnumType="ReportFormType" Required="1"></Parent><Choice Name="ReportProcessingWay" Index="980005" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="OutputFormat" Index="980006" Description="Выходной формат"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_EXTRA_TEMPLATE"><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="ExtraUiCommand" Column="ExtraUiCommand"></Map><Map Name="ReportFileParameters" Column="ReportFileParameters"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map><Map Name="ReportFormType" Column="ReportFormType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_UI_ACTION_PARAMS',NULL,'Primary SQL Server','Параметр дополнительной команды',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр дополнительной команды',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_UI_ACTION_PARAMS" Description="Параметр дополнительной команды" PrimaryKey="ExtraUiActionParamsID" DNAttributes="{Name};{ParamDescription}" DisplayName="{0} - {1}"><Fields><Attribute Name="ExtraUiActionParamsID" Index="1020001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="1020003" Description="Наименование" Required="1"></Attribute><Attribute Name="ParamDescription" Index="1020004" Description="Описание" Required="1"></Attribute><Attribute Name="IsOutput" Index="1020005" Type="bool" Description="Выходной параметр" Required="1"></Attribute><Attribute Name="ParamValue" Index="1020006" Type="text" Description="Значение"></Attribute><Attribute Name="OutputOrder" Index="1020008" Type="int" Description="Порядок отображения"></Attribute><Attribute Name="FileName" Index="1020009" Type="string" Description="Наименование файла результата" CharacterMaximumLength="255"></Attribute><Parent Name="ExtraUiCommand" Index="1020002" Type="VCLib.EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" Required="1"></Parent><Choice Name="ResultType" Index="1020007" Description="Тип результата"><Item Name="Предпросмотр" Index="0"></Item><Item Name="Файл" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_EXTRA_UI_ACTION_PARAMS"><Map Name="ExtraUiActionParamsID" Column="ExtraUiActionParamsID"></Map><Map Name="ExtraUiCommand" Column="ExtraUiCommand"></Map><Map Name="Name" Column="Name"></Map><Map Name="ParamDescription" Column="ParamDescription"></Map><Map Name="IsOutput" Column="IsOutput"></Map><Map Name="ParamValue" Column="ParamValue"></Map><Map Name="ResultType" Column="ResultType"></Map><Map Name="OutputOrder" Column="OutputOrder"></Map><Map Name="FileName" Column="FileName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_UI_COMMAND',NULL,'Primary SQL Server','Дополнительная команда пользовательского интерфейса',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Дополнительная команда пользовательского интерфейса',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" PrimaryKey="ExtraUiCommandID" DNAttributes="{Name};{CommandType}" DisplayName="{1} - {0}"><Fields><Attribute Name="ExtraUiCommandID" Index="990001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="990002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="FilterValue" Index="990003" Type="text" Description="Значение фильтра"></Attribute><Attribute Name="Context" Index="990004" Type="string" Description="Контекст"></Attribute><Attribute Name="OpenContext" Index="990005" Type="string" Description="Контекст обработки команды"></Attribute><Attribute Name="Priority" Index="990006" Type="int" Description="Приоритет отображения" Required="1"></Attribute><Attribute Name="StyleType" Index="990007" Type="string" Description="Стиль"></Attribute><Attribute Name="SameObject" Index="990013" Type="bool" Description="Обрабатывать текущий объект" Required="1"></Attribute><Attribute Name="StoredProcedure" Index="990014" Type="string" Description="Наименование хранимой процедуры"></Attribute><Attribute Name="DisplayAttributes" Index="990018" Type="string" Description="Атрибуты заголовка формы" CharacterMaximumLength="1000"></Attribute><Attribute Name="RemoteCommandID" Index="990021" Type="string" Description="Идентификатор команды на удаленном сервере" CharacterMaximumLength="36"></Attribute><Attribute Name="SingleObject" Index="990022" Type="bool" Description="Только для одного объекта" Cashed="1"></Attribute><Parent Name="Entities" Index="990008" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Parent Name="CommandEntity" Index="990009" Type="VCLib.ENTITIES" Description="Сущность обработки команды" Required="1"></Parent><Parent Name="Credentials" Index="990019" Type="VCLib.CREDENTIALS" Description="Информация об учетной записи"></Parent><Child Name="ExtraUiCommandRoless" Index="990012" Type="VCLib.EXTRA_UI_COMMAND_ROLES" Description="Роли с доступом к дополнительным командам" ChildAttribute="ExtraUiCommand"></Child><Child Name="ExtraUiActionParams" Index="990015" Type="VCLib.EXTRA_UI_ACTION_PARAMS" Description="Параметры процедуры действия" ChildAttribute="ExtraUiCommand"></Child><Choice Name="CommandType" Index="990010" Description="Тип команды" Required="1"><Item Name="Фильтр" Index="0"></Item><Item Name="Связанный список" Index="1"></Item><Item Name="Отчет" Index="2"></Item><Item Name="Открыть форму" Index="3"></Item><Item Name="Действие" Index="4"></Item><Item Name="Редактировать" Index="5"></Item><Item Name="Команды модальной формы" Index="6"></Item></Choice><Choice Name="ExecutionType" Index="990020" Description="Тип обработки" Required="1"><Item Name="Internal" Index="0"></Item><Item Name="External" Index="1"></Item></Choice><Link Name="ExtraTemplate" Index="990011" Type="VCLib.EXTRA_TEMPLATE" Description="Шаблон пользовательских списков" LinkAttribute="ExtraUiCommand"></Link></Fields><DbMapping><Table name="T_EXTRA_UI_COMMAND"><Map Name="ExtraUiCommandID" Column="ExtraUiCommandID"></Map><Map Name="Name" Column="Name"></Map><Map Name="FilterValue" Column="FilterValue"></Map><Map Name="Context" Column="Context"></Map><Map Name="OpenContext" Column="OpenContext"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="StyleType" Column="StyleType"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="CommandEntity" Column="CommandEntity"></Map><Map Name="CommandType" Column="CommandType"></Map><Map Name="SameObject" Column="SameObject"></Map><Map Name="StoredProcedure" Column="StoredProcedure"></Map><Map Name="DisplayAttributes" Column="DisplayAttributes"></Map><Map Name="Credentials" Column="Credentials"></Map><Map Name="ExecutionType" Column="ExecutionType"></Map><Map Name="RemoteCommandID" Column="RemoteCommandID"></Map></Table><Lexem><Map Name="SingleObject"><lx:Case xmlns:lx="lexem"><When><lx:CriterionChildExists entity="VCLib.EXTRA_UI_ACTION_PARAMS" top="-1" xmlns:lx="lexem"><condition><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="1020005" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></lx:Criterion></condition><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="990015" xmlns:lx="lexem"></lx:StepInt></lx:Path></lx:CriterionChildExists></When><Then><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></Then><Else><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[False]]></lx:ConstOperand></Else></lx:Case></Map></Lexem></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND_ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_UI_COMMAND_ROLES',NULL,'Primary SQL Server','Роли с доступом к дополнительным командам',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Роли с доступом к дополнительным командам',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND_ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_UI_COMMAND_ROLES" Description="Роли с доступом к дополнительным командам" PrimaryKey="ExtraUiCommandRolesID"><Fields><Attribute Name="ExtraUiCommandRolesID" Index="1010001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="ExtraUiCommand" Index="1010002" Type="VCLib.EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" Required="1"></Parent><Parent Name="Roles" Index="1010003" Type="VCLib.ROLES" Description="Роли пользователей в системе" Required="1"></Parent></Fields><DbMapping><Table name="T_EXTRA_UI_COMMAND_ROLES"><Map Name="ExtraUiCommandRolesID" Column="ExtraUiCommandRolesID"></Map><Map Name="ExtraUiCommand" Column="ExtraUiCommand"></Map><Map Name="Roles" Column="Roles"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_UI_COMMAND_ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='FILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'FILE',NULL,'Primary SQL Server','Файл',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Файл',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='FILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="FILE" Description="Файл" PrimaryKey="FileID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="FileID" Index="3200001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3200002" Type="string" Description="Имя файла" Required="1"></Attribute><Attribute Name="FileDescription" Index="3200003" Type="string" Description="Описание" CharacterMaximumLength="1024"></Attribute><Attribute Name="Content" Index="3200004" Type="binary" Description="Содержимое файла" Required="1"></Attribute><Attribute Name="CreateDateTime" Index="3200005" Type="datetime" Description="Дата создания" DefaultFormat="{0:dd.MM.yyyy HH:mm}"></Attribute><Attribute Name="Folder" Index="3200006" Type="string" Description="Папка"></Attribute><Attribute Name="FileHash" Index="3200008" Type="string" Description="Хэш" CharacterMaximumLength="50"></Attribute><Choice Name="FileNameForm" Index="3200007" Description="Формат наименования файла" Required="1"><Item Name="Идентификатор" Index="0"></Item><Item Name="Наименование" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_FILE"><Map Name="FileID" Column="FileID"></Map><Map Name="Name" Column="Name"></Map><Map Name="FileDescription" Column="FileDescription"></Map><Map Name="CreateDateTime" Column="CreateDateTime"></Map><Map Name="Folder" Column="Folder"></Map><Map Name="FileNameForm" Column="FileNameForm"></Map><Map Name="FileHash" Column="FileHash"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='FILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='FILES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'FILES',NULL,'Primary SQL Server','Файл',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Файл',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='FILES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="FILES" Description="Файл" version="2" PrimaryKey="FileID" DNAttributes="{FileName}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="FileID" Index="180001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="FileName" Index="180003" Type="string" Description="Имя файла"></Attribute><Attribute Name="Contents" Index="180004" Type="binary" Description="Содержимое"></Attribute><Attribute Name="Description" Index="180005" Type="string" Description="Описание"></Attribute></Fields><CalculatingAttributes><Attribute Name="FileSize" Index="180006" Type="int" Description="Размер файла"></Attribute></CalculatingAttributes><DbMapping><Table name="T_FILES"><Map Name="FileID" Column="FileID"></Map><Map Name="FileName" Column="FileName"></Map><Map Name="Contents" Column="Contents"></Map><Map Name="Description" Column="Description"></Map><Map Name="FileSize" Function="dbo.fn_GetFileSize"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='FILES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='HIDDEN_ATTRIBUTE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'HIDDEN_ATTRIBUTE',NULL,'Primary SQL Server','Скрытый аттрибут',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Скрытый аттрибут',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='HIDDEN_ATTRIBUTE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="HIDDEN_ATTRIBUTE" Description="Скрытый аттрибут" PrimaryKey="HiddenAttributeID"><Fields><Attribute Name="HiddenAttributeID" Index="2490001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="AttributeIndex" Index="2490003" Type="int" Description="Индекс аттрибута" Required="1"></Attribute><Parent Name="Entities" Index="2490002" Type="VCLib.ENTITIES" Description="Сущность" Required="1"></Parent><Child Name="RoleAttributeAccesss" Index="2490004" Type="VCLib.ROLE_ATTRIBUTE_ACCESS" Description="Роли с исключительным доступом" ChildAttribute="HiddenAttribute"></Child></Fields><DbMapping><Table name="T_HIDDEN_ATTRIBUTE"><Map Name="HiddenAttributeID" Column="HiddenAttributeID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="AttributeIndex" Column="AttributeIndex"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="AttributeName" Index="2490005" Description="Наименование атрибута" RequiredAttributes="{AttributeIndex};{Entities}"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='HIDDEN_ATTRIBUTE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='HOLDER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'HOLDER',NULL,'Primary SQL Server','Холдер',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Холдер',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='HOLDER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="HOLDER" Description="Холдер" PrimaryKey="HolderID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="HolderID" Index="100001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="Name" Index="100003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Description" Index="100004" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="IsClient" Index="100005" Type="bool" Description="Клиентский холдер" Required="1"></Attribute><Child Name="HolderParameters" Index="100006" Type="VCLib.HOLDER_PARAMETER" Description="Параметр холдера" ChildAttribute="Holder"></Child><Child Name="HolderStartupCustoms" Index="100007" Type="VCLib.HOLDER_STARTUP_CUSTOM" Description="Исключительный тип запуска холдера" ChildAttribute="Holder"></Child></Fields><DbMapping><Table name="T_HOLDER"><Map Name="HolderID" Column="HolderID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Description" Column="Description"></Map><Map Name="IsClient" Column="IsClient"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='HOLDER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'HOLDER_PARAMETER',NULL,'Primary SQL Server','Параметр холдера',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр холдера',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="HOLDER_PARAMETER" Description="Параметр холдера" PrimaryKey="HolderParameterID" DNAttributes="{ParameterName}" DisplayName="Параметр {0}"><Fields><Attribute Name="HolderParameterID" Index="170001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="ParameterName" Index="170003" Type="string" Description="Наименование параметра" Required="1"></Attribute><Attribute Name="ParameterValue" Index="170004" Type="string" Description="Значение параметра" CharacterMaximumLength="8000"></Attribute><Attribute Name="Description" Index="170006" Type="string" Description="Описание" Required="1"></Attribute><Parent Name="Holder" Index="170002" Type="VCLib.HOLDER" Description="Холдер" Required="1"></Parent><Child Name="HolderParameterCustoms" Index="170005" Type="VCLib.HOLDER_PARAMETER_CUSTOM" Description="Исключительный параметр холдера" ChildAttribute="HolderParameter"></Child></Fields><DbMapping><Table name="T_HOLDER_PARAMETER"><Map Name="HolderParameterID" Column="HolderParameterID"></Map><Map Name="Holder" Column="Holder"></Map><Map Name="ParameterName" Column="ParameterName"></Map><Map Name="ParameterValue" Column="ParameterValue"></Map><Map Name="Description" Column="Description"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER_CUSTOM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'HOLDER_PARAMETER_CUSTOM',NULL,'Primary SQL Server','Исключительный параметр холдера',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Исключительный параметр холдера',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER_CUSTOM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="HOLDER_PARAMETER_CUSTOM" Description="Исключительный параметр холдера" PrimaryKey="HolderParameterCustomID"><Fields><Attribute Name="HolderParameterCustomID" Index="200001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="CustomValue" Index="200003" Type="string" Description="Значение" CharacterMaximumLength="8000" Required="1"></Attribute><Parent Name="HolderParameter" Index="200002" Type="VCLib.HOLDER_PARAMETER" Description="Параметр холдера" Required="1"></Parent><Parent Name="Servers" Index="200004" Type="VCLib.SERVERS" Description="Сервер" Required="1"></Parent></Fields><DbMapping><Table name="T_HOLDER_PARAMETER_CUSTOM"><Map Name="HolderParameterCustomID" Column="HolderParameterCustomID"></Map><Map Name="HolderParameter" Column="HolderParameter"></Map><Map Name="CustomValue" Column="CustomValue"></Map><Map Name="Servers" Column="Servers"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='HOLDER_PARAMETER_CUSTOM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='HOLDER_STARTUP_CUSTOM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'HOLDER_STARTUP_CUSTOM',NULL,'Primary SQL Server','Исключительный тип запуска холдера',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Исключительный тип запуска холдера',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='HOLDER_STARTUP_CUSTOM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="HOLDER_STARTUP_CUSTOM" Description="Исключительный тип запуска холдера" PrimaryKey="HolderStartupCustomID"><Fields><Attribute Name="HolderStartupCustomID" Index="500001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Parent Name="Holder" Index="500002" Type="VCLib.HOLDER" Description="Холдер" Required="1"></Parent><Parent Name="Servers" Index="500003" Type="VCLib.SERVERS" Description="Сервер"></Parent><Choice Name="StartupType" Index="500004" Description="Тип запуска" Required="1"><Item Name="Automatic" Index="0"></Item><Item Name="Manual" Index="1"></Item><Item Name="Disabled" Index="2"></Item><Item Name="Delayed" Index="3"></Item></Choice></Fields><DbMapping><Table name="T_HOLDER_STARTUP_CUSTOM"><Map Name="HolderStartupCustomID" Column="HolderStartupCustomID"></Map><Map Name="Holder" Column="Holder"></Map><Map Name="Servers" Column="Servers"></Map><Map Name="StartupType" Column="StartupType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='HOLDER_STARTUP_CUSTOM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='MACHINE_CONFIG')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MACHINE_CONFIG',NULL,'Primary SQL Server','Настройки компьютера',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройки компьютера',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='MACHINE_CONFIG'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="MACHINE_CONFIG" Description="Настройки компьютера" version="2" PrimaryKey="MachineConfigID" UnrestrictedAccess="1"><Fields><Attribute Name="MachineConfigID" Index="3610001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="MachineName" Index="3610002" Type="string" Description="Название компьютера" CharacterMaximumLength="256"></Attribute><Attribute Name="ConfigValue" Index="3610003" Type="text" Description="Конфигурация"></Attribute></Fields><DbMapping><Table name="T_MACHINE_CONFIG"><Map Name="MachineConfigID" Column="MachineConfigID"></Map><Map Name="MachineName" Column="MachineName"></Map><Map Name="ConfigValue" Column="ConfigValue"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='MACHINE_CONFIG'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='MENU_COMMAND')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'MENU_COMMAND',NULL,'Primary SQL Server','Команда меню',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Команда меню',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='MENU_COMMAND'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="MENU_COMMAND" Description="Команда меню" PrimaryKey="MenuID"><Fields><Attribute Name="MenuID" Index="510001" Type="guid" Description="Идентификатор"></Attribute></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='MENU_COMMAND'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='PROCESS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PROCESS',NULL,'Primary SQL Server','Процесс',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Процесс',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='PROCESS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="PROCESS" Description="Процесс" version="2" PrimaryKey="guid" UnrestrictedAccess="1"><CalculatingAttributes><Attribute Name="CheckAccess" Index="320002" Type="bool" Description="Check access flag"></Attribute><Attribute Name="Count" Index="320003" Type="int" Description="Child processes count"></Attribute><Attribute Name="Data" Index="320004" Type="binary" Description="Non-serialized custom data"></Attribute><Attribute Name="guid" Index="320005" Type="guid" Description="Unique process identifier"></Attribute><Attribute Name="InitializedFromServer" Index="320006" Type="bool" Description="Shows whether this process was initialized by server or not"></Attribute><Attribute Name="Name" Index="320007" Type="string" Description="Process name"></Attribute><Attribute Name="NeedContinueOnServer" Index="320008" Type="bool" Description="Restore frozen process on server"></Attribute><Attribute Name="NeedReturn" Index="320009" Type="bool" Description="Need return identity after save"></Attribute><Attribute Name="NeedReturnObject" Index="320010" Type="bool" Description="Need return object from server to client"></Attribute><Attribute Name="Object" Index="320011" Type="object" Description="Business object"></Attribute><Attribute Name="SendOnServer" Index="320014" Type="bool" Description="Prevent process from sending from client to server"></Attribute><Attribute Name="StopProcessing" Index="320015" Type="bool" Description="Immediately stop processing after return from process handler"></Attribute><Attribute Name="WaitForClientResponse" Index="320018" Type="bool" Description="Wait for client response on the server side"></Attribute><Attribute Name="SeparateRunOfGroupProcess" Index="320019" Type="bool" Description="Execution type of group processes"></Attribute><Parent Name="ParentProcess" Index="320013" Type="VCLib.PROCESS" Description="Parent process"></Parent><Parent Name="TransactionProcess" Index="320017" Type="VCLib.PROCESS" Description="Transaction process"></Parent><Child Name="SubProcesses" Index="320016" Type="VCLib.PROCESS" Description="Child processes collection"></Child></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='PROCESS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='PROCESS_ACCESS_ENTRY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'PROCESS_ACCESS_ENTRY',NULL,'Primary SQL Server','Право доступа к процессу',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право доступа к процессу',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BASE_ACCESS_ENTRY') WHERE [Schema]='VCLib' and EntName='PROCESS_ACCESS_ENTRY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="PROCESS_ACCESS_ENTRY" Description="Право доступа к процессу" version="2" PrimaryKey="EntryID" UnrestrictedAccess="1" Inherits="VCLib.BASE_ACCESS_ENTRY"><Fields><Attribute Name="LexemContent" Index="260001" Type="string" Description="Лексема"></Attribute><Attribute Name="ProcessName" Index="260002" Type="string" Description="Имя процесса"></Attribute><Attribute Name="Priority" Index="260003" Type="int" Description="Приоритет" Required="1"></Attribute><Attribute Name="CheckInputObject" Index="260006" Type="bool" Description="Флаг проверки входного объекта" Required="1"></Attribute><Attribute Name="CheckDBObject" Index="260007" Type="bool" Description="Флаг проверки объекта из БД" Required="1"></Attribute><Parent Name="EntityID" Index="260005" Type="VCLib.ENTITIES" Description="Сущность данных" Save="0"></Parent><Choice Name="Flags" Index="260004" Description="Флаги доступа" Required="1"><Item Name="Запрещен" Index="0"></Item><Item Name="Разрешен" Index="1"></Item><Item Name="Разрешен, как не головной" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_PROCESS_ACCESS_ENTRY"><Map Name="LexemContent" Column="LexemContent"></Map><Map Name="ProcessName" Column="ProcessName"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="Flags" Column="Flags"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="CheckInputObject" Column="CheckInputObject"></Map><Map Name="CheckDBObject" Column="CheckDbObject"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='PROCESS_ACCESS_ENTRY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ProcessDescription')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ProcessDescription',NULL,'Primary SQL Server','Описание процесса',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Описание процесса',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ProcessDescription'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ProcessDescription" Description="Описание процесса" version="2" PrimaryKey="ProcessDescriptionID" DNAttributes="{HRDescription}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="ProcessDescriptionID" Index="690001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="690002" Type="string" Description="Наименование процесса" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="HRDescription" Index="690003" Type="string" Description="Описание процесса" CharacterMaximumLength="255" Required="1"></Attribute></Fields><DbMapping><Table name="T_PROCESSDESCRIPTION"><Map Name="ProcessDescriptionID" Column="ProcessDescriptionID"></Map><Map Name="Name" Column="Name"></Map><Map Name="HRDescription" Column="HRDescription"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ProcessDescription'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ROLE_ATTRIBUTE_ACCESS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ROLE_ATTRIBUTE_ACCESS',NULL,'Primary SQL Server','Исключительный доступ роли к аттрибуту сущности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Исключительный доступ роли к аттрибуту сущности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ROLE_ATTRIBUTE_ACCESS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ROLE_ATTRIBUTE_ACCESS" Description="Исключительный доступ роли к аттрибуту сущности" PrimaryKey="RoleAttributeAccessID"><Fields><Attribute Name="RoleAttributeAccessID" Index="2500001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="HiddenAttribute" Index="2500002" Type="VCLib.HIDDEN_ATTRIBUTE" Description="Скрытый аттрибут" Required="1"></Parent><Parent Name="RoleID" Index="2500003" Type="VCLib.ROLES" Description="Роль" Required="1"></Parent></Fields><DbMapping><Table name="T_ROLE_ATTRIBUTE_ACCESS"><Map Name="RoleAttributeAccessID" Column="RoleAttributeAccessID"></Map><Map Name="HiddenAttribute" Column="HiddenAttribute"></Map><Map Name="RoleID" Column="RoleID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ROLE_ATTRIBUTE_ACCESS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ROLE_CLIENT_MODULES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ROLE_CLIENT_MODULES',NULL,'Primary SQL Server','Сущность-связка между ROLES и CLIENT_MODULES',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сущность-связка между ROLES и CLIENT_MODULES',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ROLE_CLIENT_MODULES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ROLE_CLIENT_MODULES" Description="Сущность-связка между ROLES и CLIENT_MODULES" version="2" PrimaryKey="RoleClientModuleID" UnrestrictedAccess="0"><Fields><Attribute Name="RoleClientModuleID" Index="230001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="LoadOrder" Index="230004" Type="int" Description="Порядок загрузки" Required="1"></Attribute><Parent Name="ClientModuleID" Index="230002" Type="VCLib.CLIENT_MODULES" Description="Модуль"></Parent><Parent Name="RoleID" Index="230003" Type="VCLib.ROLES" Description="Роль"></Parent><Child Name="BaseFeatureSettingss" Index="230005" Type="VCLib.BASE_FEATURE_SETTINGS" Description="Подключенные настройки клиентского модуля" ChildAttribute="RoleClientModules"></Child></Fields><DbMapping><Table name="T_ROLE_CLIENT_MODULES"><Map Name="RoleClientModuleID" Column="RoleClientModuleID"></Map><Map Name="ClientModuleID" Column="ClientModuleID"></Map><Map Name="RoleID" Column="RoleID"></Map><Map Name="LoadOrder" Column="LoadOrder"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ROLE_CLIENT_MODULES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ROLES',NULL,'Primary SQL Server','Роли пользователей в системе',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Роли пользователей в системе',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ROLES" Description="Роли пользователей в системе" version="2" PrimaryKey="RoleID" DNAttributes="{RoleName}" DisplayName="{0}" UnrestrictedAccess="1"><Customs><Custom Name="uniqueness" Value="(90002)"></Custom></Customs><Fields><Attribute Name="RoleID" Index="90001" Type="guid" Description="Идентификатор роли"></Attribute><Attribute Name="RoleName" Index="90002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="RoleDesc" Index="90003" Type="string" Description="Описание"></Attribute><Attribute Name="DivisionsLevel" Index="90008" Type="int" Description="Уровень подразделения" Required="1"></Attribute><Parent Name="Departament" Index="90004" Type="VCLib.ENUMS" Description="Отдел" EnumType="Departament"></Parent><Child Name="ROLE_USERS" Index="90005" Type="VCLib.USERS_ROLES" Description="Пользователи" ChildAttribute="RoleID" RemoveAction="0"></Child><Child Name="ROLE_ACCESS" Index="90006" Type="VCLib.BAE_ROLES" Description="Права" ChildAttribute="RoleID" RemoveAction="0"></Child><Child Name="ROLE_MODULES" Index="90007" Type="VCLib.ROLE_CLIENT_MODULES" Description="Модули" ChildAttribute="RoleID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_ROLES"><Map Name="RoleID" Column="RoleID"></Map><Map Name="RoleName" Column="RoleName"></Map><Map Name="RoleDesc" Column="RoleDesc"></Map><Map Name="Departament" Column="Departament"></Map><Map Name="DivisionsLevel" Column="DivisionsLevel"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SCHEMA')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SCHEMA',NULL,'Primary SQL Server','Схема',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Схема',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SCHEMA'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SCHEMA" Description="Схема" PrimaryKey="SchemaName"><Fields><Attribute Name="SchemaName" Index="450001" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Priority" Index="450002" Type="int" Description="Приоритет загрузки" Required="1"></Attribute></Fields><DbMapping><Table name="T_SCHEMA"><Map Name="SchemaName" Column="SchemaName"></Map><Map Name="Priority" Column="Priority"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SCHEMA'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SERVER_ROUTING_RULE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SERVER_ROUTING_RULE',NULL,'Primary SQL Server','Правило роутинга серверов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Правило роутинга серверов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SERVER_ROUTING_RULE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SERVER_ROUTING_RULE" Description="Правило роутинга серверов" PrimaryKey="RuleID"><Fields><Attribute Name="RuleID" Index="2160001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ObjectName" Index="2160002" Type="string" Description="Объект процесса"></Attribute><Attribute Name="ProcessName" Index="2160005" Type="string" Description="Имя процесса" Required="1"></Attribute><Parent Name="ServerFrom" Index="2160003" Type="VCLib.SERVERS" Description="Сервер, передающий процесс" Required="1"></Parent><Parent Name="ServerTo" Index="2160004" Type="VCLib.SERVERS" Description="Сервер, принимающий процесс" Required="1"></Parent></Fields><DbMapping><Table name="T_SERVER_ROUTING_RULE"><Map Name="RuleID" Column="RuleID"></Map><Map Name="ObjectName" Column="ObjectName"></Map><Map Name="ServerFrom" Column="ServerFrom"></Map><Map Name="ServerTo" Column="ServerTo"></Map><Map Name="ProcessName" Column="ProcessName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SERVER_ROUTING_RULE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ShortcutCommand')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ShortcutCommand',NULL,'Primary SQL Server','Настройка горячей клавиши',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка горячей клавиши',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ShortcutCommand'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ShortcutCommand" Description="Настройка горячей клавиши" version="2" PrimaryKey="ShortcutId" DNAttributes="{CommandName};{Keys}" DisplayName="{0} - {1}" UnrestrictedAccess="1"><Fields><Attribute Name="ShortcutId" Index="340001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CommandName" Index="340002" Type="string" Description="Название команды" Required="1"></Attribute><Attribute Name="Keys" Index="340003" Type="string" Description="Сочетание клавиш" Required="1"></Attribute><Attribute Name="FormType" Index="340004" Type="string" Description="Тип формы"></Attribute><Attribute Name="Context" Index="340005" Type="string" Description="Контекст"></Attribute><Attribute Name="StronglyCached" Index="340007" Type="bool" Description="Кэширован на клиенте в обязательном порядке"></Attribute><Parent Name="User" Index="340006" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent></Fields><DbMapping><Table name="T_SHORTCUTCOMMAND"><Map Name="ShortcutId" Column="ShortcutId"></Map><Map Name="CommandName" Column="CommandName"></Map><Map Name="Keys" Column="Keys"></Map><Map Name="User" Column="UserId"></Map><Map Name="FormType" Column="FormType"></Map><Map Name="Context" Column="Context"></Map><Map Name="StronglyCached" Column="StronglyCached"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ShortcutCommand'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TEMPLATE_FIELD',NULL,'Primary SQL Server','Шаблон поля',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон поля',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TEMPLATE_FIELD" Description="Шаблон поля" PrimaryKey="TemplateFieldID" DNAttributes="{Entity/EntDesc};{AttributeName}" DisplayName="{0}/{1}"><Fields><Attribute Name="TemplateFieldID" Index="3010001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="AttrPath" Index="3010003" Type="string" Description="Путь к атрибуту" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="UsersValuesOnly" Index="3010007" Type="bool" Description="Только свои значения"></Attribute><Attribute Name="CopyAttributes" Index="3010008" Type="string" Description="Копируемые атрибуты" CharacterMaximumLength="8000"></Attribute><Attribute Name="LoadPrompts" Index="3010010" Type="bool" Description="Предоставлять список возможных вариантов"></Attribute><Parent Name="Entity" Index="3010002" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="TemplateFieldValues" Index="3010004" Type="VCLib.TEMPLATE_FIELD_VALUE" Description="Строки шаблона" ChildAttribute="TemplateField" SortingAttr="Name"></Child></Fields><DbMapping><Table name="T_TEMPLATE_FIELD"><Map Name="TemplateFieldID" Column="TemplateFieldID"></Map><Map Name="Entity" Column="Entity"></Map><Map Name="AttrPath" Column="AttrPath"></Map><Map Name="UsersValuesOnly" Column="UsersValuesOnly"></Map><Map Name="CopyAttributes" Column="CopyAttributes"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="AttributeName" Index="3010005" Type="string" Description="Атрибут" RequiredAttributes="{Entity};{AttrPath}"></Attribute><Choice Name="TemplateFieldType" Index="3010009" Description="Тип шаблона" RequiredAttributes="{AttrPath};{Entity}"><Item Name="Текстовый" Index="0"></Item><Item Name="Копирование записи" Index="1"></Item></Choice></CalculatingAttributes><Customs><Custom Name="NotDisplayedInFilter" Value="LoadPrompts"></Custom><Custom Name="NotDisplayedColumns" Value="LoadPrompts"></Custom><Custom Name="NotTrackedAttributes" Value="LoadPrompts"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD_VALUE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TEMPLATE_FIELD_VALUE',NULL,'Primary SQL Server','Значение шаблона',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Значение шаблона',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD_VALUE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TEMPLATE_FIELD_VALUE" Description="Значение шаблона" PrimaryKey="TemplateFieldValueID"><Fields><Attribute Name="TemplateFieldValueID" Index="3020001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3020004" Type="string" Description="Наименование"></Attribute><Attribute Name="TemplateString" Index="3020005" Type="string" Description="Строка шаблона" CharacterMaximumLength="7000"></Attribute><Attribute Name="Category" Index="3020006" Type="string" Description="Категория"></Attribute><Attribute Name="TextFontSize" Index="3020011" Type="int" Description="Размер шрифта"></Attribute><Parent Name="TemplateField" Index="3020002" Type="VCLib.TEMPLATE_FIELD" Description="Шаблон поля" Required="1"></Parent><Parent Name="Users" Index="3020003" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent><Parent Name="UsersGroup" Index="3020008" Type="VCLib.USERS_GROUP" Description="Группы пользователей"></Parent><Choice Name="TextValueType" Index="3020010" Description="Тип шаблона" Required="1"><Item Name="Текстовый шаблон" Index="0"></Item><Item Name="Список вводившихся значений" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_TEMPLATE_FIELD_VALUE"><Map Name="TemplateFieldValueID" Column="TemplateFieldValueID"></Map><Map Name="TemplateField" Column="TemplateField"></Map><Map Name="TemplateString" Column="TemplateString"></Map><Map Name="Users" Column="Users"></Map><Map Name="Name" Column="Name"></Map><Map Name="Category" Column="Category"></Map><Map Name="UsersGroup" Column="UsersGroup"></Map><Map Name="TextValueType" Column="TextValueType"></Map><Map Name="TextFontSize" Column="TextFontSize"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="UserName" Index="3020007" Type="string" Description="Имя пользователя" RequiredAttributes="{TemplUser/UserName}"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='TEMPLATE_FIELD_VALUE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TRACE_EVENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TRACE_EVENT',NULL,'Primary SQL Server','Событие трассировки',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Событие трассировки',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='TRACE_EVENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TRACE_EVENT" Description="Событие трассировки" PrimaryKey="TraceEventId"><Fields><Attribute Name="TraceEventId" Index="520001" Type="guid" Description="Идентификатор" Required="1"></Attribute><Attribute Name="EventType" Index="520002" Type="string" Description="Тип события"></Attribute><Attribute Name="EventSession" Index="520003" Type="guid" Description="Сессия событий"></Attribute><Attribute Name="StartTime" Index="520004" Type="datetime" Description="Время начала события"></Attribute><Attribute Name="StopTime" Index="520005" Type="datetime" Description="Время окончания события"></Attribute><Attribute Name="TextData" Index="520006" Type="text" Description="Текст"></Attribute><Attribute Name="ProcessId" Index="520007" Type="guid" Description="Имя процесса"></Attribute><Attribute Name="ProcessName" Index="520008" Type="string" Description="Имя процесса"></Attribute><Attribute Name="ProcessObject" Index="520009" Type="string" Description="Объект процесса"></Attribute><Attribute Name="ProcessObjectId" Index="520010" Type="string" Description="Объект процесса"></Attribute><Attribute Name="ProcessParentId" Index="520011" Type="guid" Description="Имя процесса"></Attribute><Attribute Name="ProcessHeadId" Index="520012" Type="guid" Description="Имя процесса"></Attribute><Attribute Name="ProcessRootId" Index="520013" Type="guid" Description="Имя процесса"></Attribute><Attribute Name="ServerId" Index="520014" Type="guid" Description="Идентификатор сервера"></Attribute><Attribute Name="ThreadId" Index="520015" Type="int" Description="Идентификатор потока"></Attribute><Attribute Name="ThreadName" Index="520016" Type="string" Description="Идентификатор потока"></Attribute><Attribute Name="UserName" Index="520017" Type="string" Description="Имя пользователя"></Attribute><Attribute Name="UserSession" Index="520018" Type="string" Description="Сессия пользователя"></Attribute></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='TRACE_EVENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USER_COLUMNS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USER_COLUMNS',NULL,'Primary SQL Server','Настройки колонок',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройки колонок',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USER_COLUMNS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USER_COLUMNS" Description="Настройки колонок" version="2" PrimaryKey="UserColsID" DNAttributes="{ColumnName}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="UserColsID" Index="20001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="AttributePath" Index="20002" Type="string" Description="Путь к атрибуту"></Attribute><Attribute Name="ColumnName" Index="20003" Type="string" Description="Отображаемое имя колонки"></Attribute><Attribute Name="ColumnIndex" Index="20004" Type="int" Description="Индекс колонки в списке"></Attribute><Attribute Name="ColumnWidth" Index="20005" Type="int" Description="Ширина колонки в списке"></Attribute><Attribute Name="Visible" Index="20006" Type="bool" Description="Показывать колонку"></Attribute><Attribute Name="SortingIndex" Index="20008" Type="int" Description="Позиция в сортировке"></Attribute><Parent Name="UserContextID" Index="20007" Type="VCLib.USER_CONTEXTS" Description="Контекст" Required="1"></Parent><Choice Name="Sorting" Index="20009" Description="Сортировка" Required="1"><Item Name="Отсутствует" Index="0"></Item><Item Name="По возрастанию" Index="1"></Item><Item Name="По убыванию" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_USER_COLUMNS"><Map Name="UserColsID" Column="UserColsID"></Map><Map Name="AttributePath" Column="AttributePath"></Map><Map Name="ColumnName" Column="DisplayName"></Map><Map Name="ColumnIndex" Column="ColumnIndex"></Map><Map Name="ColumnWidth" Column="ColumnWidth"></Map><Map Name="Visible" Column="Visible"></Map><Map Name="SortingIndex" Column="SortingIndex"></Map><Map Name="Sorting" Column="Sorting"></Map><Map Name="UserContextID" Column="UserContextID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USER_COLUMNS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USER_CONTEXTS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USER_CONTEXTS',NULL,'Primary SQL Server','Пользовательский контекст',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Пользовательский контекст',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USER_CONTEXTS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USER_CONTEXTS" Description="Пользовательский контекст" version="2" PrimaryKey="UserContextID" UnrestrictedAccess="1"><Fields><Attribute Name="UserContextID" Index="30001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Context" Index="30002" Type="string" Description="Контекст вызова"></Attribute><Attribute Name="ShowPreview" Index="30003" Type="boolean" Description="Показывать превью"></Attribute><Attribute Name="PreviewRatio" Index="30007" Type="float" Description="Отношение высоты панели preview к высоте формы стд. списка"></Attribute><Attribute Name="ShowGrid" Index="30008" Type="bool" Description="Отображать сетку" Required="1"></Attribute><Attribute Name="ScalePercent" Index="30009" Type="int" Description="Масштаб"></Attribute><Parent Name="EntityID" Index="30004" Type="VCLib.ENTITIES" Description="Сущность данных" Required="1" Save="0"></Parent><Parent Name="UserID" Index="30005" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent><Child Name="USER_COL_CONT" Index="30006" Type="VCLib.USER_COLUMNS" Description="Настройки колонок" ChildAttribute="UserContextID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_USER_CONTEXTS"><Map Name="UserContextID" Column="UserContextID"></Map><Map Name="Context" Column="Context"></Map><Map Name="ShowPreview" Column="ShowPreview"></Map><Map Name="PreviewRatio" Column="PreviewRatio"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="UserID" Column="UserID"></Map><Map Name="ShowGrid" Column="ShowGrid"></Map><Map Name="ScalePercent" Column="ScalePercent"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USER_CONTEXTS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USER_SEARCHES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USER_SEARCHES',NULL,'Primary SQL Server','Сохраненные фильтры пользователей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сохраненные фильтры пользователей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USER_SEARCHES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USER_SEARCHES" Description="Сохраненные фильтры пользователей" version="2" PrimaryKey="SearchID" DNAttributes="{SearchName}" DisplayName="{0}" UnrestrictedAccess="0"><Fields><Attribute Name="SearchID" Index="40001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="SearchName" Index="40002" Type="string" Description="Наименование фильтра"></Attribute><Attribute Name="FilterValue" Index="40004" Type="text" Description="Значение фильтра"></Attribute><Attribute Name="HasParent" Index="40009" Type="bool" Description="Существует фильтр с пользователем более высокого уровня доступа."><Parameter Name="DivisionID" Type="object" Description="Подразделение"><lx:ParamHolder xmlns:lx="lexem"><lx:StepString name="CURRENT_USER_DIVISION" xmlns:lx="lexem"></lx:StepString></lx:ParamHolder></Parameter></Attribute><Attribute Name="HasChild" Index="40010" Type="bool" Description="Существует фильтр с пользователем более низкого уровня доступа."><Parameter Name="DivisionID" Type="object" Description="Подразделение"><lx:ParamHolder xmlns:lx="lexem"><lx:StepString name="CURRENT_USER_DIVISION" xmlns:lx="lexem"></lx:StepString></lx:ParamHolder></Parameter></Attribute><Parent Name="EntityID" Index="40005" Type="VCLib.ENTITIES" Description="Сущность данных" Save="0"></Parent><Parent Name="UserID" Index="40006" Type="VCLib.BASE_USERS" Description="Пользователь" Required="1"></Parent><Choice Name="ShareFilter" Index="40007" Description="Фильтр виден" Required="1"><Item Name="Мне (текущий пользователь)" Index="0"></Item><Item Name="Подразделению пользователя" Index="1"></Item><Item Name="Всем (подразделению пользователя и всем дочерним)" Index="2"></Item></Choice><Choice Name="Filters" Index="40008" Description="Фильтр" IsFlag="1"><Parameter Name="DivisionID" Type="object" Description="Подразделение"><lx:ParamHolder xmlns:lx="lexem"><lx:StepString name="CURRENT_USER_DIVISION" xmlns:lx="lexem"></lx:StepString></lx:ParamHolder></Parameter><Parameter Name="UserID" Type="object" Description="Пользователь"><lx:ParamHolder xmlns:lx="lexem"><lx:StepString name="CURRENT_USER" xmlns:lx="lexem"></lx:StepString></lx:ParamHolder></Parameter><Item Name="На пользователя" Index="1"></Item><Item Name="На подразделение" Index="2"></Item><Item Name="На подраздления выше" Index="4"></Item><Item Name="На подразделения ниже" Index="8"></Item></Choice></Fields><DbMapping><Table name="T_USER_SEARCHES"><Map Name="SearchID" Column="SearchID"></Map><Map Name="SearchName" Column="SearchName"></Map><Map Name="FilterValue" Column="FilterValue"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="UserID" Column="UserID"></Map><Map Name="ShareFilter" Column="ShareFilter"></Map></Table><Lexem><Map Name="Filters"><lx:Block xmlns:lx="lexem"><lx:LexemList xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable></lx:LexemList><lx:LexemList xmlns:lx="lexem"><lx:Assign xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:ConstOperand type="Decimal" xmlns:lx="lexem"><![CDATA[0]]></lx:ConstOperand></lx:Assign><lx:Case xmlns:lx="lexem"><When><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40006" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Argument xmlns:lx="lexem"><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[1]]></lx:ConstOperand></lx:Argument></lx:Criterion></When><Then><lx:Assign xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:MathOperator sign="|" xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:ConstOperand type="Decimal" xmlns:lx="lexem"><![CDATA[1]]></lx:ConstOperand></lx:MathOperator></lx:Assign></Then></lx:Case><lx:Case xmlns:lx="lexem"><When><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40006" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="50017" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="330001" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Argument xmlns:lx="lexem"><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[0]]></lx:ConstOperand></lx:Argument></lx:Criterion></When><Then><lx:Assign xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:MathOperator sign="|" xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:ConstOperand type="Decimal" xmlns:lx="lexem"><![CDATA[2]]></lx:ConstOperand></lx:MathOperator></lx:Assign></Then></lx:Case><lx:Case xmlns:lx="lexem"><When><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40010" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></lx:Criterion></When><Then><lx:Assign xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:MathOperator sign="|" xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:ConstOperand type="Decimal" xmlns:lx="lexem"><![CDATA[4]]></lx:ConstOperand></lx:MathOperator></lx:Assign></Then></lx:Case><lx:Case xmlns:lx="lexem"><When><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40009" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></lx:Criterion></When><Then><lx:Assign xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:MathOperator sign="|" xmlns:lx="lexem"><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable><lx:ConstOperand type="Decimal" xmlns:lx="lexem"><![CDATA[8]]></lx:ConstOperand></lx:MathOperator></lx:Assign></Then></lx:Case><lx:Variable Name="a" Level="0" xmlns:lx="lexem"></lx:Variable></lx:LexemList><lx:LexemList xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40006" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="50017" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="330001" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40010" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40009" xmlns:lx="lexem"></lx:StepInt></lx:Path></lx:LexemList></lx:Block></Map><Map Name="HasParent"><lx:Case xmlns:lx="lexem"><When><lx:TreeQuery EntityName="VCLib.DIVISIONS" QueryType="HaveChild" xmlns:lx="lexem"><path><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40006" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="50017" xmlns:lx="lexem"></lx:StepInt></lx:Path></path><condition><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="330001" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Argument xmlns:lx="lexem"><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[0]]></lx:ConstOperand></lx:Argument></lx:Criterion></condition></lx:TreeQuery></When><Then><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></Then><Else><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[False]]></lx:ConstOperand></Else></lx:Case></Map><Map Name="HasChild"><lx:Case xmlns:lx="lexem"><When><lx:TreeQuery EntityName="VCLib.DIVISIONS" QueryType="HaveParent" xmlns:lx="lexem"><path><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="40006" xmlns:lx="lexem"></lx:StepInt><lx:StepInt index="50017" xmlns:lx="lexem"></lx:StepInt></lx:Path></path><condition><lx:Criterion type="=" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepInt index="330001" xmlns:lx="lexem"></lx:StepInt></lx:Path><lx:Argument xmlns:lx="lexem"><lx:ConstOperand type="Int32" xmlns:lx="lexem"><![CDATA[0]]></lx:ConstOperand></lx:Argument></lx:Criterion></condition></lx:TreeQuery></When><Then><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[True]]></lx:ConstOperand></Then><Else><lx:ConstOperand type="Boolean" xmlns:lx="lexem"><![CDATA[False]]></lx:ConstOperand></Else></lx:Case></Map></Lexem></DbMapping><Customs><Custom Name="NotDisplayedInFilter" Value="HasParent;HasChild;Filters"></Custom><Custom Name="NotDisplayedColumns" Value="HasParent;HasChild;Filters"></Custom><Custom Name="NotTrackedAttributes" Value="HasParent;HasChild;Filters"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='USER_SEARCHES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USERS_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USERS_GROUP',NULL,'Primary SQL Server','Группы пользователей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группы пользователей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USERS_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USERS_GROUP" Description="Группы пользователей" PrimaryKey="UsersGroupID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="UsersGroupID" Index="3530001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3530002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Filter" Index="3530003" Type="text" Description="Фильтр"></Attribute></Fields><DbMapping><Table name="T_USERS_GROUP"><Map Name="UsersGroupID" Column="UsersGroupID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Filter" Column="Filter"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USERS_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USERS_ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USERS_ROLES',NULL,'Primary SQL Server','Распределение пользователей по ролям',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Распределение пользователей по ролям',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USERS_ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USERS_ROLES" Description="Распределение пользователей по ролям" version="2" PrimaryKey="UserRoleID" UnrestrictedAccess="1"><Fields><Attribute Name="UserRoleID" Index="80001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="RoleID" Index="80002" Type="VCLib.ROLES" Description="Роль"></Parent><Parent Name="UserID" Index="80003" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent></Fields><DbMapping><Table name="T_USERS_ROLES"><Map Name="UserRoleID" Column="UserRoleID"></Map><Map Name="RoleID" Column="RoleID"></Map><Map Name="UserID" Column="UserID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USERS_ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SERVERS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SERVERS',NULL,'Primary SQL Server','Сервер',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сервер',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SERVERS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SERVERS" Description="Сервер" version="2" PrimaryKey="ServerID" DNAttributes="{ServerName}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="ServerID" Index="2430001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ServerName" Index="2430002" Type="string" Description="Наименование"></Attribute><Attribute Name="Active" Index="2430003" Type="boolean" Description="Активный"></Attribute><Attribute Name="IsMain" Index="2430004" Type="bool" Description="Главный сервер" Required="1"></Attribute><Attribute Name="Address" Index="2430005" Type="string" Description="Адрес сервера" Required="1"></Attribute><Child Name="IncomeRules" Index="2430006" Type="VCLib.SERVER_ROUTING_RULE" Description="Правила входящих процессов" ChildAttribute="ServerTo"></Child><Child Name="OutcomeRules" Index="2430007" Type="VCLib.SERVER_ROUTING_RULE" Description="Правила исходящих процессов" ChildAttribute="ServerFrom"></Child></Fields><DbMapping><Table name="T_SERVERS"><Map Name="ServerID" Column="ServerID"></Map><Map Name="ServerName" Column="ServerName"></Map><Map Name="Active" Column="Active"></Map><Map Name="IsMain" Column="IsMain"></Map><Map Name="Address" Column="Address"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SERVERS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USER_CONFIG')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USER_CONFIG',NULL,'Primary SQL Server','Связь Пользователь-Конфигурация',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь Пользователь-Конфигурация',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USER_CONFIG'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USER_CONFIG" Description="Связь Пользователь-Конфигурация" version="2" PrimaryKey="ID" UnrestrictedAccess="1"><Fields><Attribute Name="ID" Index="2480001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ConfigValue" Index="2480002" Type="text" Description="Конфигурация"></Attribute><Parent Name="UserID" Index="2480003" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent></Fields><DbMapping><Table name="T_USER_CONFIG"><Map Name="ID" Column="ID"></Map><Map Name="ConfigValue" Column="ConfigValue"></Map><Map Name="UserID" Column="UserID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USER_CONFIG'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='USER_SESSIONS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'USER_SESSIONS',NULL,'Primary SQL Server','Сессии пользователей при работе с системой',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сессии пользователей при работе с системой',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='USER_SESSIONS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="USER_SESSIONS" Description="Сессии пользователей при работе с системой" version="2" PrimaryKey="USessionID" UnrestrictedAccess="1"><Fields><Attribute Name="USessionID" Index="2210001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Login" Index="2210002" Type="datetime" Description="Дата входа в систему"></Attribute><Attribute Name="Logout" Index="2210003" Type="datetime" Description="Дата и время выхода пользователя из системы"></Attribute><Attribute Name="Application" Index="2210004" Type="string" Description="Приложение, из которого произошел вход в систему"></Attribute><Attribute Name="ClientComputer" Index="2210005" Type="string" Description="Компьютер пользователя"></Attribute><Parent Name="UserID" Index="2210006" Type="VCLib.BASE_USERS" Description="Пользователь"></Parent><Parent Name="ServerID" Index="2210007" Type="VCLib.SERVERS" Description="Сервер"></Parent></Fields><DbMapping><Table name="T_USER_SESSIONS"><Map Name="USessionID" Column="USessionID"></Map><Map Name="Login" Column="Login"></Map><Map Name="Logout" Column="Logout"></Map><Map Name="Application" Column="Application"></Map><Map Name="ClientComputer" Column="ClientComputer"></Map><Map Name="UserID" Column="UserID"></Map><Map Name="ServerID" Column="ServerID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='USER_SESSIONS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='FILE_REPORT_MENU_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'FILE_REPORT_MENU_ITEM',NULL,'Primary SQL Server','Ссылка на отчет из файла',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на отчет из файла',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM') WHERE [Schema]='VCLib' and EntName='FILE_REPORT_MENU_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="FILE_REPORT_MENU_ITEM" Description="Ссылка на отчет из файла" Inherits="VCLib.REPORT_MENU_ITEM"><Fields><Parent Name="GenericReportFile" Index="3540001" Type="VCLib.GENERIC_REPORT_FILE" Description="Отчет из файла" Required="1"></Parent></Fields><DbMapping><Table name="T_FILE_REPORT_MENU_ITEM"><Map Name="GenericReportFile" Column="GenericReportFile"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='FILE_REPORT_MENU_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MENU_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_MENU_ITEM',NULL,'Primary SQL Server','Ссылка на генератор отчетов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на генератор отчетов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MENU_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_MENU_ITEM" Description="Ссылка на генератор отчетов" Inherits="VCLib.REPORT_MENU_ITEM"><Fields><Parent Name="Report" Index="3260001" Type="VCLib.GENERIC_REPORT_MAIN" Description="Отчет" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERIC_REPORT_MENU_ITEM"><Map Name="Report" Column="Report"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MENU_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='REPORT_MENU_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REPORT_MENU_ITEM',NULL,'Primary SQL Server','Ссылка меню на отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка меню на отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='REPORT_MENU_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="REPORT_MENU_ITEM" Description="Ссылка меню на отчет" PrimaryKey="ReportMenuItemID"><Fields><Attribute Name="ReportMenuItemID" Index="3230001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3230003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="OrderNum" Index="3230004" Type="string" Description="Порядковый номер" Required="1"></Attribute></Fields><DbMapping><Table name="T_REPORT_MENU_ITEM"><Map Name="ReportMenuItemID" Column="ReportMenuItemID"></Map><Map Name="Name" Column="Name"></Map><Map Name="OrderNum" Column="OrderNum"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='REPORT_MENU_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SIMPLE_REPORT_MENU_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SIMPLE_REPORT_MENU_ITEM',NULL,'Primary SQL Server','Ссылка на простой отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на простой отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'REPORT_MENU_ITEM') WHERE [Schema]='VCLib' and EntName='SIMPLE_REPORT_MENU_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SIMPLE_REPORT_MENU_ITEM" Description="Ссылка на простой отчет" Inherits="VCLib.REPORT_MENU_ITEM"><Fields><Parent Name="Report" Index="3250001" Type="VCLib.Report" Description="Отчет" Required="1"></Parent></Fields><DbMapping><Table name="T_SIMPLE_REPORT_MENU_ITEM"><Map Name="Report" Column="Report"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SIMPLE_REPORT_MENU_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='AUTHENTICATION_AUDIT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'AUTHENTICATION_AUDIT',NULL,'Primary SQL Server','Аудит аутентификации пользователей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Аудит аутентификации пользователей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='AUTHENTICATION_AUDIT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="AUTHENTICATION_AUDIT" Description="Аудит аутентификации пользователей" PrimaryKey="AuthenticationAuditID" DNAttributes="{RegisterTime};{Login}" DisplayName="{0} / {1}"><Fields><Attribute Name="AuthenticationAuditID" Index="3270001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="RegisterTime" Index="3270002" Type="datetime" Description="Время события" DefaultFormat="{0:dd.MM.yyyy HH:mm:ss}" Required="1"></Attribute><Attribute Name="UnregisterTime" Index="3270003" Type="datetime" Description="Время отключения" DefaultFormat="{0:dd.MM.yyyy HH:mm:ss}"></Attribute><Attribute Name="ComputerName" Index="3270004" Type="string" Description="Имя компьютера" CharacterMaximumLength="100" Required="1"></Attribute><Attribute Name="Ip" Index="3270005" Type="string" Description="IP адрес компьютера" CharacterMaximumLength="40" Required="1"></Attribute><Attribute Name="Login" Index="3270006" Type="string" Description="Логин" CharacterMaximumLength="50" Required="1"></Attribute><Attribute Name="ServerSessionId" Index="3270011" Type="guid" Description="Серверная сессия"></Attribute><Attribute Name="RemoteDomain" Index="3270012" Type="string" Description="Название домена" CharacterMaximumLength="256"></Attribute><Attribute Name="RemoteIp" Index="3270013" Type="string" Description="Удалённый IP" CharacterMaximumLength="32"></Attribute><Attribute Name="RemoteComputerName" Index="3270014" Type="string" Description="Название удалённого компьютера" CharacterMaximumLength="256"></Attribute><Attribute Name="RemoteUserName" Index="3270015" Type="string" Description="Имя пользователя" CharacterMaximumLength="256"></Attribute><Choice Name="RegisterType" Index="3270008" Description="Тип события / подключения" Required="1"><Item Name="Подключение к системе" Index="0"></Item><Item Name="Пользователь не зарегистрирован" Index="1"></Item><Item Name="Неправильный пароль" Index="2"></Item><Item Name="Пользователь заблокирован" Index="3"></Item></Choice><Choice Name="UnregisterType" Index="3270009" Description="Тип отключения"><Item Name="Пользовательский" Index="0"></Item><Item Name="По таймауту" Index="1"></Item><Item Name="Отключение сервера" Index="2"></Item></Choice><Choice Name="AuthenticationType" Index="3270010" Description="Тип аутентификации" Required="1"><Item Name="Системная аутентификация" Index="0"></Item><Item Name="Windows аутентификация" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_AUTHENTICATION_AUDIT"><Map Name="AuthenticationAuditID" Column="AuthenticationAuditID"></Map><Map Name="RegisterTime" Column="RegisterTime"></Map><Map Name="UnregisterTime" Column="UnregisterTime"></Map><Map Name="ComputerName" Column="ComputerName"></Map><Map Name="Ip" Column="Ip"></Map><Map Name="Login" Column="Login"></Map><Map Name="RegisterType" Column="RegisterType"></Map><Map Name="UnregisterType" Column="UnregisterType"></Map><Map Name="AuthenticationType" Column="AuthenticationType"></Map><Map Name="ServerSessionId" Column="ServerSessionId"></Map><Map Name="RemoteIp" Column="RemoteIp"></Map><Map Name="RemoteComputerName" Column="RemoteComputerName"></Map><Map Name="RemoteUserName" Column="RemoteUserName"></Map><Map Name="RemoteDomain" Column="RemoteDomain"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='AUTHENTICATION_AUDIT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DELETED_OBJECT',NULL,'Primary SQL Server','Удаленный объект',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Удаленный объект',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DELETED_OBJECT" Description="Удаленный объект" PrimaryKey="DeletedObjectID"><Fields><Attribute Name="DeletedObjectID" Index="470001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DeleteDateTime" Index="470003" Type="datetime" Description="Дата и время" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Required="1"></Attribute><Attribute Name="ObjectId" Index="470005" Type="string" Description="Идентификатор объекта" CharacterMaximumLength="64" Required="1"></Attribute><Attribute Name="ObjectInfo" Index="470006" Type="string" Description="Информация об объекте" CharacterMaximumLength="1000"></Attribute><Parent Name="Users" Index="470002" Type="VCLib.BASE_USERS" Description="Пользователь системы" Required="1"></Parent><Parent Name="Entities" Index="470004" Type="VCLib.ENTITIES" Description="Сущность" Required="1"></Parent></Fields><DbMapping><Table name="T_DELETED_OBJECT"><Map Name="DeletedObjectID" Column="DeletedObjectID"></Map><Map Name="Users" Column="Users"></Map><Map Name="DeleteDateTime" Column="DeleteDateTime"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="ObjectId" Column="ObjectId"></Map><Map Name="ObjectInfo" Column="ObjectInfo"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT_INFO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DELETED_OBJECT_INFO',NULL,'Primary SQL Server','Настройка сохранения текстовой информации об удаленных объектах',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка сохранения текстовой информации об удаленных объектах',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT_INFO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DELETED_OBJECT_INFO" Description="Настройка сохранения текстовой информации об удаленных объектах" PrimaryKey="DeletedObjectInfoID"><Fields><Attribute Name="DeletedObjectInfoID" Index="480001" Type="int" Description="Идентификатор"></Attribute><Attribute Name="Lexem" Index="480003" Type="text" Description="Лексема для получения информации об объекте" Required="1"></Attribute><Parent Name="Entities" Index="480002" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent></Fields><DbMapping><Table name="T_DELETED_OBJECT_INFO"><Map Name="DeletedObjectInfoID" Column="Entities"></Map><Map Name="Entities" Column="Entities" IsStored="0"></Map><Map Name="Lexem" Column="Lexem"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DELETED_OBJECT_INFO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SECURITY_AUDIT',NULL,'Primary SQL Server','Аудит безопасности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Аудит безопасности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SECURITY_AUDIT" Description="Аудит безопасности" PrimaryKey="SecurityAuditID"><Fields><Attribute Name="SecurityAuditID" Index="3280001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ClientSessionId" Index="3280003" Type="guid" Description="Клиентская сессия" Required="1"></Attribute><Attribute Name="EventDateTime" Index="3280004" Type="datetime" Description="Время события" Required="1"></Attribute><Attribute Name="UserName" Index="3280005" Type="string" Description="Имя пользователя" Required="1"></Attribute><Child Name="SecurityAuditChangesets" Index="3280002" Type="VCLib.SECURITY_AUDIT_CHANGESET" Description="Набор изменений в аудите безопасности" ChildAttribute="SecurityAudit" Required="1"></Child></Fields><DbMapping><Table name="T_SECURITY_AUDIT"><Map Name="SecurityAuditID" Column="SecurityAuditID"></Map><Map Name="ClientSessionId" Column="ClientSessionId"></Map><Map Name="EventDateTime" Column="EventDateTime"></Map><Map Name="UserName" Column="UserName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT_CHANGESET')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SECURITY_AUDIT_CHANGESET',NULL,'Primary SQL Server','Изменения аудита безопасности',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Изменения аудита безопасности',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT_CHANGESET'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SECURITY_AUDIT_CHANGESET" Description="Изменения аудита безопасности" PrimaryKey="SecurityAuditChangesetID"><Fields><Attribute Name="SecurityAuditChangesetID" Index="3320001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ObjectName" Index="3320005" Type="string" Description="Наименование объекта" Required="1"></Attribute><Attribute Name="Descr" Index="3320007" Type="text" Description="Описание"></Attribute><Attribute Name="TargetName" Index="3320008" Type="string" Description="Имя целевого объекта" Required="1"></Attribute><Parent Name="SecurityAudit" Index="3320002" Type="VCLib.SECURITY_AUDIT" Description="Аудит безопасности" Required="1"></Parent><Choice Name="TargetType" Index="3320004" Description="Цель" Required="1"><Item Name="Объект" Index="0"></Item><Item Name="Роль" Index="1"></Item></Choice><Choice Name="EventObject" Index="3320009" Description="Объект события" Required="1"><Item Name="Пользователь" Index="0"></Item><Item Name="Клиентский модуль" Index="1"></Item></Choice><Choice Name="ActionType" Index="3320010" Description="Тип действия" Required="1"><Item Name="Добавление" Index="0"></Item><Item Name="Удаление" Index="1"></Item><Item Name="Изменение" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_SECURITY_AUDIT_CHANGESET"><Map Name="SecurityAuditChangesetID" Column="SecurityAuditChangesetID"></Map><Map Name="SecurityAudit" Column="SecurityAudit"></Map><Map Name="TargetType" Column="TargetType"></Map><Map Name="ObjectName" Column="ObjectName"></Map><Map Name="ActionType" Column="ActionType"></Map><Map Name="Descr" Column="Descr"></Map><Map Name="TargetName" Column="TargetName"></Map><Map Name="EventObject" Column="EventObject"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SECURITY_AUDIT_CHANGESET'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SERVER_SESSION_AUDIT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SERVER_SESSION_AUDIT',NULL,'Primary SQL Server','Аудит сессий сервера',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Аудит сессий сервера',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SERVER_SESSION_AUDIT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SERVER_SESSION_AUDIT" Description="Аудит сессий сервера" PrimaryKey="ServerSessionAuditID"><Fields><Attribute Name="ServerSessionAuditID" Index="3290001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="StartTime" Index="3290002" Type="datetime" Description="Время запуска" DefaultFormat="{0:dd.MM.yyyy HH:mm:ss}" Required="1"></Attribute><Attribute Name="StopTime" Index="3290003" Type="datetime" Description="Время остановки" DefaultFormat="{0:dd.MM.yyyy HH:mm:ss}"></Attribute><Attribute Name="ComputerName" Index="3290005" Type="string" Description="Имя компьютера" CharacterMaximumLength="100"></Attribute><Attribute Name="UserName" Index="3290006" Type="string" Description="Имя пользователя" CharacterMaximumLength="100"></Attribute><Attribute Name="Domain" Index="3290007" Type="string" Description="Домен" CharacterMaximumLength="100"></Attribute><Attribute Name="ServerVersion" Index="3290008" Type="string" Description="Версия сервера" CharacterMaximumLength="50"></Attribute><Attribute Name="OSVersion" Index="3290009" Type="string" Description="Версия ОС" CharacterMaximumLength="50"></Attribute><Attribute Name="CLRVersion" Index="3290010" Type="string" Description="Версия CLR приложения" CharacterMaximumLength="50"></Attribute><Attribute Name="ArchVersion" Index="3290011" Type="string" Description="Архитектура приложения" CharacterMaximumLength="50"></Attribute><Parent Name="Servers" Index="3290012" Type="VCLib.SERVERS" Description="Сервер"></Parent><Choice Name="StopType" Index="3290004" Description="Тип остановки"><Item Name="Запланированный" Index="0"></Item><Item Name="С ошибкой" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_SERVER_SESSION_AUDIT"><Map Name="ServerSessionAuditID" Column="ServerSessionAuditID"></Map><Map Name="StartTime" Column="StartTime"></Map><Map Name="StopTime" Column="StopTime"></Map><Map Name="StopType" Column="StopType"></Map><Map Name="ComputerName" Column="ComputerName"></Map><Map Name="UserName" Column="UserName"></Map><Map Name="Domain" Column="Domain"></Map><Map Name="ServerVersion" Column="ServerVersion"></Map><Map Name="OSVersion" Column="OSVersion"></Map><Map Name="CLRVersion" Column="CLRVersion"></Map><Map Name="ArchVersion" Column="ArchVersion"></Map><Map Name="Servers" Column="Servers"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SERVER_SESSION_AUDIT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'UNITED_OBJECT',NULL,'Primary SQL Server','Объединенный объект',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Объединенный объект',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="UNITED_OBJECT" Description="Объединенный объект" PrimaryKey="UnitedObjectID"><Fields><Attribute Name="UnitedObjectID" Index="210001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CreateDate" Index="210003" Type="datetime" Description="Дата создания" DefaultFormat="{0:dd.MM.yyyy HH:mm:ss}" Required="1"></Attribute><Attribute Name="ObjectID" Index="210005" Type="string" Description="Идентификатор объекта" CharacterMaximumLength="256" Required="1"></Attribute><Parent Name="Entities" Index="210002" Type="VCLib.ENTITIES" Description="Сущности метаданных" Required="1"></Parent><Parent Name="BaseUsers" Index="210004" Type="VCLib.BASE_USERS" Description="Пользователь" Required="1"></Parent><Child Name="UnitedObjectChangesets" Index="210006" Type="VCLib.UNITED_OBJECT_CHANGESET" Description="Изменения объединенного объекта" ChildAttribute="UnitedObject"></Child></Fields><DbMapping><Table name="T_UNITED_OBJECT"><Map Name="UnitedObjectID" Column="UnitedObjectID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="CreateDate" Column="CreateDate"></Map><Map Name="BaseUsers" Column="BaseUsers"></Map><Map Name="ObjectID" Column="ObjectID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT_CHANGESET')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'UNITED_OBJECT_CHANGESET',NULL,'Primary SQL Server','Изменения объединенного объекта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Изменения объединенного объекта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT_CHANGESET'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="UNITED_OBJECT_CHANGESET" Description="Изменения объединенного объекта" PrimaryKey="UnitedObjectChangesetID"><Fields><Attribute Name="UnitedObjectChangesetID" Index="280001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ObjectID" Index="280004" Type="string" Description="Идентификатор объекта" CharacterMaximumLength="256" Required="1"></Attribute><Parent Name="UnitedObject" Index="280002" Type="VCLib.UNITED_OBJECT" Description="Объединенный объект" Required="1"></Parent><Parent Name="Entities" Index="280005" Type="VCLib.ENTITIES" Description="Сущности метаданных" Required="1"></Parent><Choice Name="ChangeType" Index="280003" Description="Тип изменения" Required="1"><Item Name="Объединение" Index="0"></Item><Item Name="Удаление" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_UNITED_OBJECT_CHANGESET"><Map Name="UnitedObjectChangesetID" Column="UnitedObjectChangesetID"></Map><Map Name="UnitedObject" Column="UnitedObject"></Map><Map Name="ChangeType" Column="ChangeType"></Map><Map Name="ObjectID" Column="ObjectID"></Map><Map Name="Entities" Column="Entities"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='UNITED_OBJECT_CHANGESET'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='BaseReport')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'BaseReport',NULL,'Primary SQL Server','Базовый тип для отчетов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Базовый тип для отчетов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='BaseReport'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="BaseReport" Description="Базовый тип для отчетов" version="2" PrimaryKey="ReportID" DNAttributes="{RepName}" DisplayName="{0}" UnrestrictedAccess="0"><Customs><Custom Name="uniqueness" Value="(600002)"></Custom></Customs><Fields><Attribute Name="ReportID" Index="600001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="RepName" Index="600002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="RepDesc" Index="600003" Type="string" Description="Описание"></Attribute><Attribute Name="Active" Index="600004" Type="bool" Description="Активный" Required="1"></Attribute><Child Name="Access" Index="600005" Type="VCLib.ReportRole" Description="Права доступа к отчету по ролям" ChildAttribute="ReportID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_BaseReport"><Map Name="ReportID" Column="ReportID"></Map><Map Name="RepName" Column="RepName"></Map><Map Name="RepDesc" Column="RepDesc"></Map><Map Name="Active" Column="Active"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='BaseReport'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='Report')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'Report',NULL,'Primary SQL Server','Отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BaseReport'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BaseReport') WHERE [Schema]='VCLib' and EntName='Report'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="Report" Description="Отчет" version="2" PrimaryKey="ReportID" Inherits="VCLib.BaseReport"><Fields><Attribute Name="ForcedFetchAttrs" Index="160005" Type="text" Description="Атрибуты принудительной зачитки"></Attribute><Attribute Name="FilterValue" Index="160006" Type="text" Description="Фильтр отчета"></Attribute><Attribute Name="Sorting" Index="160020" Type="text" Description="Атрибуты сортировки"></Attribute><Attribute Name="Descending" Index="160021" Type="int" Description="Направление сортировки"></Attribute><Attribute Name="ScriptName" Index="160023" Type="string" Description="Имя скрипта для загрузки данных"></Attribute><Parent Name="EntityID" Index="160014" Type="VCLib.ENTITIES" Description="Тип данных"></Parent><Parent Name="ReportLoadDataType" Index="160015" Type="VCLib.ENUMS" Description="Способ формирования данных для отчета" EnumType="ReportLoadDataType" Required="1"></Parent><Parent Name="ReportFormType" Index="160019" Type="VCLib.ENUMS" Description="Тип вывода объектов в документы" EnumType="ReportFormType" Required="1"></Parent><Child Name="FileGroups" Index="160008" Type="VCLib.ReportFileGroup" Description="Группы файлов" ChildAttribute="ReportID" RemoveAction="0"></Child><Child Name="Keys" Index="160010" Type="VCLib.ReportKey" Description="Параметры отчета" ChildAttribute="ReportID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_Report"><Map Name="ForcedFetchAttrs" Column="ForcedFetchAttrs"></Map><Map Name="FilterValue" Column="FilterValue"></Map><Map Name="Sorting" Column="Sorting"></Map><Map Name="Descending" Column="Descending"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="ReportFormType" Column="ReportFormType"></Map><Map Name="ReportLoadDataType" Column="ReportLoadDataType"></Map><Map Name="ScriptName" Column="ScriptName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='Report'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportFile')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportFile',NULL,'Primary SQL Server','Шаблон документа отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон документа отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='ReportFile'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportFile" Description="Шаблон документа отчета" version="2" UnrestrictedAccess="1" Inherits="VCLib.FILES"><Fields><Attribute Name="IsSecondary" Index="110003" Type="bool" Description="Не обрабатывать"></Attribute><Attribute Name="OutputName" Index="110006" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="GroupID" Index="110001" Type="VCLib.ReportFileGroup" Description="Комплект шаблонов"></Parent><Parent Name="RepFmtID" Index="110002" Type="VCLib.ReportFileFormat" Description="Формат" Required="1"></Parent><Child Name="Parameters" Index="110004" Type="VCLib.ReportFileParameter" Description="Пераметры, используемые в шаблоне" ChildAttribute="FileID" RemoveAction="0"></Child><Choice Name="OutputFormat" Index="110005" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice><Choice Name="ProcessingWay" Index="8570006" Description="Способ обработки" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_ReportFile"><Map Name="GroupID" Column="GroupID"></Map><Map Name="RepFmtID" Column="RepFmtID"></Map><Map Name="IsSecondary" Column="IsSecondary"></Map><Map Name="ProcessingWay" Column="ProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportFile'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportFileFormat')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportFileFormat',NULL,'Primary SQL Server','Форматы отчетов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Форматы отчетов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ReportFileFormat'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportFileFormat" Description="Форматы отчетов" version="2" PrimaryKey="RepFmtID" DNAttributes="{Name}" DisplayName="{0}" UnrestrictedAccess="1"><Fields><Attribute Name="RepFmtID" Index="120001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="120002" Type="string" Description="Наименование"></Attribute><Attribute Name="HandlerName" Index="120003" Type="string" Description="Обработчик"></Attribute><Child Name="Files" Index="120004" Type="VCLib.ReportFile" Description="Шаблоны выходных документов" ChildAttribute="RepFmtID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_ReportFileFormat"><Map Name="RepFmtID" Column="RepFmtID"></Map><Map Name="Name" Column="Name"></Map><Map Name="HandlerName" Column="HandlerName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportFileFormat'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportFileGroup')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportFileGroup',NULL,'Primary SQL Server','Группа шаблонов документов отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группа шаблонов документов отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ReportFileGroup'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportFileGroup" Description="Группа шаблонов документов отчета" version="2" PrimaryKey="GroupID" UnrestrictedAccess="1"><Customs><Custom Name="uniqueness" Value="(140002;140003)"></Custom></Customs><Fields><Attribute Name="GroupID" Index="140001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="140002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="IsDefault" Index="140006" Type="bool" Description="Используется по умолчанию"></Attribute><Parent Name="ReportID" Index="140003" Type="VCLib.Report" Description="Отчет"></Parent><Child Name="Files" Index="140005" Type="VCLib.ReportFile" Description="Файлы" ChildAttribute="GroupID" RemoveAction="0"></Child></Fields><DbMapping><Table name="T_ReportFileGroup"><Map Name="GroupID" Column="GroupID"></Map><Map Name="Name" Column="Name"></Map><Map Name="IsDefault" Column="IsDefault"></Map><Map Name="ReportID" Column="ReportID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportFileGroup'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportFileParameter')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportFileParameter',NULL,'Primary SQL Server','Параметр шаблона документа',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр шаблона документа',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ReportFileParameter'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportFileParameter" Description="Параметр шаблона документа" version="2" PrimaryKey="ParamID" UnrestrictedAccess="1"><Fields><Attribute Name="ParamID" Index="150001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="150002" Type="string" Description="Наименование UQO"></Attribute><Attribute Name="Content" Index="150003" Type="string" Description="Строковое представление UQO"></Attribute><Parent Name="FileID" Index="150004" Type="VCLib.ReportFile" Description="Шаблон документа"></Parent></Fields><DbMapping><Table name="T_ReportFileParameter"><Map Name="ParamID" Column="ParamID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Content" Column="Content"></Map><Map Name="FileID" Column="FileID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportFileParameter'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportKey')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportKey',NULL,'Primary SQL Server','Параметр отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ReportKey'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportKey" Description="Параметр отчета" version="2" PrimaryKey="RepKeyID" UnrestrictedAccess="1"><Fields><Attribute Name="RepKeyID" Index="130001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="130002" Type="string" Description="Наименование"></Attribute><Attribute Name="Path" Index="130003" Type="string" Description="Путь"></Attribute><Attribute Name="Length" Index="130004" Type="int" Description="Длина"></Attribute><Attribute Name="CarryOver" Index="130005" Type="bool" Description="Перенос"></Attribute><Attribute Name="Lines" Index="130006" Type="int" Description="Количество строк"></Attribute><Attribute Name="Sort" Index="130007" Type="string" Description="Сортировка"></Attribute><Attribute Name="Filter" Index="130008" Type="text" Description="Фильтр"></Attribute><Parent Name="ReportID" Index="130009" Type="VCLib.Report" Description="Отчет"></Parent><Parent Name="Align" Index="130010" Type="VCLib.ENUMS" Description="Горизонтальное выравнивание" EnumType="ReportAlign"></Parent><Parent Name="VAlign" Index="130011" Type="VCLib.ENUMS" Description="Вертикальное выравнивание" EnumType="ReportVAlign"></Parent></Fields><DbMapping><Table name="T_ReportKey"><Map Name="RepKeyID" Column="RepKeyID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Path" Column="Path"></Map><Map Name="Length" Column="Length"></Map><Map Name="CarryOver" Column="CarryOver"></Map><Map Name="Lines" Column="Lines"></Map><Map Name="Sort" Column="Sort"></Map><Map Name="Filter" Column="Filter"></Map><Map Name="ReportID" Column="ReportID"></Map><Map Name="Align" Column="Align"></Map><Map Name="VAlign" Column="VAlign"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportKey'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportRole')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportRole',NULL,'Primary SQL Server','Право на отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право на отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ReportRole'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportRole" Description="Право на отчет" version="2" PrimaryKey="RepRoleID" UnrestrictedAccess="1"><Fields><Attribute Name="RepRoleID" Index="190001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="ReportID" Index="190002" Type="VCLib.BaseReport" Description="Отчет" Required="1"></Parent><Parent Name="RoleID" Index="190003" Type="VCLib.ROLES" Description="Роль" Required="1"></Parent><Parent Name="ReportRights" Index="190004" Type="VCLib.ENUMS" Description="Уровень доступа" EnumType="ReportRights" Required="1"></Parent></Fields><DbMapping><Table name="T_ReportRole"><Map Name="RepRoleID" Column="RepRoleID"></Map><Map Name="ReportID" Column="ReportID"></Map><Map Name="RoleID" Column="RoleID"></Map><Map Name="ReportRights" Column="ReportRights"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ReportRole'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REPORTS_CONFIG',NULL,'Primary SQL Server','Настройка шаблонов печатных форм',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка шаблонов печатных форм',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="REPORTS_CONFIG" Description="Настройка шаблонов печатных форм" PrimaryKey="TemplateName"><Fields><Attribute Name="TemplateName" Index="380002" Type="string" Description="Наименование шаблона" Required="1"></Attribute><Attribute Name="TemplatePath" Index="380003" Type="string" Description="Путь до файла шаблона" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="Printer" Index="380008" Type="string" Description="Принтер"></Attribute><Attribute Name="FileName" Index="380009" Type="string" Description="Наименование файла" Required="1"></Attribute><Attribute Name="OutputName" Index="380010" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="ReportFileFormat" Index="380004" Type="VCLib.ReportFileFormat" Description="Формат шаблона" Required="1"></Parent><Child Name="TemplateOverrides" Index="380007" Type="VCLib.TEMPLATE_OVERRIDE" Description="Переопределения шаблона печатной формы" ChildAttribute="ReportsConfig" SortingAttr="OverrideOrder"></Child><Choice Name="ReportProcessingWay" Index="380006" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="OutputFormat" Index="380011" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_REPORTS_CONFIG"><Map Name="TemplateName" Column="TemplateName" IsStored="0"></Map><Map Name="TemplatePath" Column="TemplatePath" IsStored="0"></Map><Map Name="ReportFileFormat" Column="ReportFileFormat" IsStored="0"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay" IsStored="0"></Map><Map Name="FileName" Column="FileName" IsStored="0"></Map><Map Name="OutputName" Column="OutputName" IsStored="0"></Map><Map Name="OutputFormat" Column="OutputFormat" IsStored="0"></Map></Table></DbMapping><Customs><Custom Name="NotDisplayedInFilter" Value="Printer"></Custom><Custom Name="NotDisplayedColumns" Value="Printer"></Custom><Custom Name="NotTrackedAttributes" Value="Printer"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='RSReport')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'RSReport',NULL,'Primary SQL Server','Отчет Reporting Services',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BaseReport'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отчет Reporting Services',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'BaseReport') WHERE [Schema]='VCLib' and EntName='RSReport'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="RSReport" Description="Отчет Reporting Services" version="2" Inherits="VCLib.BaseReport"><Fields><Attribute Name="Url" Index="610001" Type="string" Description="Путь к отчету на сервере" Required="1"></Attribute><Parent Name="Format" Index="610002" Type="VCLib.ENUMS" Description="Формат по умолчанию" EnumType="RSExportFormat" Required="1"></Parent></Fields><DbMapping><Table name="T_RSReport"><Map Name="Url" Column="Url"></Map><Map Name="Format" Column="Format"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='RSReport'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TEMPLATE_OVERRIDE',NULL,'Primary SQL Server','Переопределение шаблона печатной формы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Переопределение шаблона печатной формы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TEMPLATE_OVERRIDE" Description="Переопределение шаблона печатной формы" PrimaryKey="TemplateOverrideID"><Fields><Attribute Name="TemplateOverrideID" Index="390001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="TemplatePath" Index="390004" Type="string" Description="Путь до файла шаблона" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="Printer" Index="390005" Type="string" Description="Принтер"></Attribute><Attribute Name="OverrideOrder" Index="390008" Type="int" Description="Порядковый номер перегрузки" Required="1"></Attribute><Attribute Name="FileName" Index="390010" Type="string" Description="Наименование файла" Required="1"></Attribute><Attribute Name="OutputName" Index="390011" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="ReportsConfig" Index="390002" Type="VCLib.REPORTS_CONFIG" Description="Настройка шаблонов печатных форм" Required="1"></Parent><Parent Name="UsersGroup" Index="390003" Type="VCLib.USERS_GROUP" Description="Группы пользователей" Required="1"></Parent><Parent Name="ReportFileFormat" Index="390007" Type="VCLib.ReportFileFormat" Description="Формат шаблона" Required="1"></Parent><Choice Name="ReportProcessingWay" Index="390006" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="ConfigType" Index="390009" Description="Тип настройки" Required="1"><Item Name="Переопределение" Index="0"></Item><Item Name="Дополнительный шаблон" Index="1"></Item></Choice><Choice Name="OutputFormat" Index="390012" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_TEMPLATE_OVERRIDE"><Map Name="TemplateOverrideID" Column="TemplateOverrideID"></Map><Map Name="ReportsConfig" Column="ReportsConfig"></Map><Map Name="UsersGroup" Column="UsersGroup"></Map><Map Name="TemplatePath" Column="TemplatePath"></Map><Map Name="Printer" Column="Printer"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay"></Map><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="OverrideOrder" Column="OverrideOrder"></Map><Map Name="ConfigType" Column="ConfigType"></Map><Map Name="FileName" Column="FileName"></Map><Map Name="OutputName" Column="OutputName"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DATAFORM_VALIDATION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DATAFORM_VALIDATION',NULL,'Primary SQL Server','Настройка валидации данных',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка валидации данных',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DATAFORM_VALIDATION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DATAFORM_VALIDATION" Description="Настройка валидации данных" PrimaryKey="DataformValidationID"><Fields><Attribute Name="DataformValidationID" Index="3300001" Type="int" Description="Идентификатор"></Attribute><Parent Name="Entities" Index="3300002" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="ValidationConditions" Index="3300003" Type="VCLib.VALIDATION_CONDITION" Description="Условия валидации" ChildAttribute="DataformValidation"></Child></Fields><DbMapping><Table name="T_DATAFORM_VALIDATION"><Map Name="DataformValidationID" Column="Entities"></Map><Map Name="Entities" Column="Entities" IsStored="0"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="EntityLevel" Index="3300004" Type="int" Description="Уровень наследования сущности"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='DATAFORM_VALIDATION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='VALIDATION_CONDITION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'VALIDATION_CONDITION',NULL,'Primary SQL Server','Условие валидации',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Условие валидации',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='VALIDATION_CONDITION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="VALIDATION_CONDITION" Description="Условие валидации" PrimaryKey="ValidationConditionID"><Fields><Attribute Name="ValidationConditionID" Index="3310001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ValidationGroup" Index="3310003" Type="string" Description="Наименование группы" CharacterMaximumLength="255"></Attribute><Attribute Name="Condition" Index="3310004" Type="text" Description="Условие" Required="1"></Attribute><Attribute Name="Context" Index="3310006" Type="string" Description="Контекст" CharacterMaximumLength="255"></Attribute><Attribute Name="ValidationDescription" Index="3310007" Type="text" Description="Описание"></Attribute><Attribute Name="IsHierarchical" Index="3310008" Type="bool" Description="Учитывать иерархию" Required="1"></Attribute><Parent Name="DataformValidation" Index="3310002" Type="VCLib.DATAFORM_VALIDATION" Description="Настройка валидации данных" Required="1"></Parent><Choice Name="ValidationType" Index="3310005" Description="Тип" Required="1"><Item Name="Ошибка" Index="0"></Item><Item Name="Предупреждение" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_VALIDATION_CONDITION"><Map Name="ValidationConditionID" Column="ValidationConditionID"></Map><Map Name="DataformValidation" Column="DataformValidation"></Map><Map Name="ValidationGroup" Column="ValidationGroup"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="ValidationType" Column="ValidationType"></Map><Map Name="Context" Column="Context"></Map><Map Name="ValidationDescription" Column="ValidationDescription"></Map><Map Name="IsHierarchical" Column="IsHierarchical"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='VALIDATION_CONDITION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_MODULE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADD_DOCUMENT_LINK_MODULE',NULL,'Primary SQL Server','Связь документа с клиентскими пользователями',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь документа с клиентскими пользователями',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_MODULE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ADD_DOCUMENT_LINK_MODULE" Description="Связь документа с клиентскими пользователями" PrimaryKey="AddDocumentLinkModuleID"><Fields><Attribute Name="AddDocumentLinkModuleID" Index="3490001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="AddingDocument" Index="3490002" Type="VCLib.ADDING_DOCUMENT" Description="Сторонние документы" Required="1"></Parent><Parent Name="ClientModules" Index="3490003" Type="VCLib.CLIENT_MODULES" Description="Модули" Required="1"></Parent></Fields><DbMapping><Table name="T_ADD_DOCUMENT_LINK_MODULE"><Map Name="AddDocumentLinkModuleID" Column="AddDocumentLinkModuleID"></Map><Map Name="AddingDocument" Column="AddingDocument"></Map><Map Name="ClientModules" Column="ClientModules"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_MODULE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADD_DOCUMENT_LINK_ROLES',NULL,'Primary SQL Server','Связь документа и роли',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь документа и роли',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ADD_DOCUMENT_LINK_ROLES" Description="Связь документа и роли" PrimaryKey="AddDocumentLinkRolesID"><Fields><Attribute Name="AddDocumentLinkRolesID" Index="3510001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Roles" Index="3510002" Type="VCLib.ROLES" Description="Роли пользователей в системе" Required="1"></Parent><Parent Name="AddingDocument" Index="3510003" Type="VCLib.ADDING_DOCUMENT" Description="Сторонние документы"></Parent></Fields><DbMapping><Table name="T_ADD_DOCUMENT_LINK_ROLES"><Map Name="AddDocumentLinkRolesID" Column="AddDocumentLinkRolesID"></Map><Map Name="Roles" Column="Roles"></Map><Map Name="AddingDocument" Column="AddingDocument"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ADD_DOCUMENT_LINK_ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADDING_DOCUMENT',NULL,'Primary SQL Server','Сторонние документы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сторонние документы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ADDING_DOCUMENT" Description="Сторонние документы" PrimaryKey="AddingDocumentID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="AddingDocumentID" Index="3420001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DateCreate" Index="3420002" Type="datetime" Description="Дата создания" Required="1"></Attribute><Attribute Name="Name" Index="3420006" Type="string" Description="Наименование документа" Required="1"></Attribute><Attribute Name="Descr" Index="3420007" Type="string" Description="Описание"></Attribute><Parent Name="RecordType" Index="3420003" Type="VCLib.ENTITIES" Description="Тип записи" Save="0"></Parent><Parent Name="Creator" Index="3420016" Type="VCLib.BASE_USERS" Description="Создатель документа"></Parent><Child Name="NewsBoxLinkAddDocuments" Index="3420013" Type="VCLib.NEWS_BOX_LINK_ADD_DOCUMENT" Description="Связь новостной ленты с документами" ChildAttribute="AddingDocument"></Child><Child Name="AddDocumentLinkModules" Index="3420014" Type="VCLib.ADD_DOCUMENT_LINK_MODULE" Description="Связь документа с клиентскими пользователями" ChildAttribute="AddingDocument"></Child><Child Name="AddDocumentLinkRoless" Index="3420017" Type="VCLib.ADD_DOCUMENT_LINK_ROLES" Description="Связь документа и роли" ChildAttribute="AddingDocument"></Child><Choice Name="CreatorType" Index="3420015" Description="Тип создателя" Required="1"><Item Name="Администрация учреждения" Index="0"></Item><Item Name="Администратор системы" Index="1"></Item><Item Name="Группа разработки" Index="2"></Item></Choice><Link Name="AddingDocumentFile" Index="3420012" Type="VCLib.ADDING_DOCUMENT_FILE" Description="Ссылка на документ" LinkAttribute="AddingDocument"></Link></Fields><DbMapping><Table name="T_ADDING_DOCUMENT"><Map Name="AddingDocumentID" Column="AddingDocumentID"></Map><Map Name="DateCreate" Column="DateCreate"></Map><Map Name="RecordType" Column="type_" IsStored="0"></Map><Map Name="Name" Column="Name"></Map><Map Name="Descr" Column="Descr"></Map><Map Name="CreatorType" Column="CreatorType"></Map><Map Name="Creator" Column="Creator"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="Type" Index="3420011" Type="int" Description="Тип"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT_FILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ADDING_DOCUMENT_FILE',NULL,'Primary SQL Server','Ссылка на документ',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на документ',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE') WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT_FILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ADDING_DOCUMENT_FILE" Description="Ссылка на документ" Inherits="VCLib.FILE"><Fields><Parent Name="AddingDocument" Index="3430001" Type="VCLib.ADDING_DOCUMENT" Description="Сторонние документы" Required="1"></Parent></Fields><DbMapping><Table name="T_ADDING_DOCUMENT_FILE"><Map Name="AddingDocument" Column="AddDocument"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ADDING_DOCUMENT_FILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX',NULL,'Primary SQL Server','Новостная информация',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Новостная информация',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX" Description="Новостная информация" PrimaryKey="NewsBoxID" DNAttributes="{DateCreate};{CreatorType}" DisplayName="Новость от {0} .Создатель {1}"><Fields><Attribute Name="NewsBoxID" Index="3450001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DateCreate" Index="3450002" Type="datetime" Description="Дата добавления" Required="1"></Attribute><Attribute Name="Description" Index="3450003" Type="text" Description="Описание"></Attribute><Parent Name="Creator" Index="3450011" Type="VCLib.BASE_USERS" Description="Создатель новости"></Parent><Child Name="NewsBoxLinkAddDocuments" Index="3450008" Type="VCLib.NEWS_BOX_LINK_ADD_DOCUMENT" Description="Связь новостной ленты с документами" ChildAttribute="NewsBox"></Child><Child Name="NewsBoxLinkModules" Index="3450009" Type="VCLib.NEWS_BOX_LINK_MODULE" Description="Идентификатор принадлежности новости модулю" ChildAttribute="NewsBox"></Child><Child Name="NewsBoxLinkUserss" Index="3450010" Type="VCLib.NEWS_BOX_LINK_USERS" Description="Идентификатор непрочитанной новости пользователем" ChildAttribute="NewsBox"></Child><Child Name="NewsBoxLinkRoless" Index="3450013" Type="VCLib.NEWS_BOX_LINK_ROLES" Description="Связь новостей с ролями" ChildAttribute="NewsBox"></Child><Child Name="NewsBoxUsersGroups" Index="3450014" Type="VCLib.NEWS_BOX_USERS_GROUP" Description="Связь новости с группой пользователей" ChildAttribute="NewsBox"></Child><Choice Name="CreatorType" Index="3450012" Description="Тип создателя" Required="1"><Item Name="Администрация учреждения" Index="0"></Item><Item Name="Администратор системы" Index="1"></Item><Item Name="Группа разработки" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_NEWS_BOX"><Map Name="NewsBoxID" Column="NewsBoxID"></Map><Map Name="DateCreate" Column="DateCreate"></Map><Map Name="Description" Column="Description"></Map><Map Name="Creator" Column="Creator"></Map><Map Name="CreatorType" Column="CreatorType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ADD_DOCUMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX_LINK_ADD_DOCUMENT',NULL,'Primary SQL Server','Связь новостной ленты с документами',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь новостной ленты с документами',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ADD_DOCUMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX_LINK_ADD_DOCUMENT" Description="Связь новостной ленты с документами" PrimaryKey="NewsBoxLinkAddDocumentID"><Fields><Attribute Name="NewsBoxLinkAddDocumentID" Index="3460001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="NewsBox" Index="3460003" Type="VCLib.NEWS_BOX" Description="Новостная информация" Required="1"></Parent><Parent Name="AddingDocument" Index="3460004" Type="VCLib.ADDING_DOCUMENT" Description="Сторонние документы" Required="1"></Parent></Fields><DbMapping><Table name="T_NEWS_BOX_LINK_ADD_DOCUMENT"><Map Name="NewsBoxLinkAddDocumentID" Column="NewsBoxLinkAddDocumentID"></Map><Map Name="NewsBox" Column="NewsBox"></Map><Map Name="AddingDocument" Column="AddingDocument"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ADD_DOCUMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_MODULE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX_LINK_MODULE',NULL,'Primary SQL Server','Идентификатор принадлежности новости модулю',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Идентификатор принадлежности новости модулю',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_MODULE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX_LINK_MODULE" Description="Идентификатор принадлежности новости модулю" PrimaryKey="NewsBoxLinkModuleID" DNAttributes="{ClientModules/ModuleDescription}" DisplayName="{0}"><Fields><Attribute Name="NewsBoxLinkModuleID" Index="3470001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="NewsBox" Index="3470002" Type="VCLib.NEWS_BOX" Description="Новостная информация" Required="1"></Parent><Parent Name="ClientModules" Index="3470003" Type="VCLib.CLIENT_MODULES" Description="Модули" Required="1"></Parent></Fields><DbMapping><Table name="T_NEWS_BOX_LINK_MODULE"><Map Name="NewsBoxLinkModuleID" Column="NewsBoxLinkModuleID"></Map><Map Name="NewsBox" Column="NewsBox"></Map><Map Name="ClientModules" Column="ClientModules"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_MODULE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ROLES')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX_LINK_ROLES',NULL,'Primary SQL Server','Связь новостей с ролями',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь новостей с ролями',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ROLES'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX_LINK_ROLES" Description="Связь новостей с ролями" PrimaryKey="NewsBoxLinkRolesID"><Fields><Attribute Name="NewsBoxLinkRolesID" Index="3500001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Roles" Index="3500003" Type="VCLib.ROLES" Description="Роли пользователей в системе" Required="1"></Parent><Parent Name="NewsBox" Index="3500004" Type="VCLib.NEWS_BOX" Description="Новостная информация" Required="1"></Parent></Fields><DbMapping><Table name="T_NEWS_BOX_LINK_ROLES"><Map Name="NewsBoxLinkRolesID" Column="NewsBoxLinkRolesID"></Map><Map Name="Roles" Column="Roles"></Map><Map Name="NewsBox" Column="NewsBox"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_ROLES'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_USERS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX_LINK_USERS',NULL,'Primary SQL Server','Идентификатор непрочитанной новости пользователем',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Идентификатор непрочитанной новости пользователем',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_USERS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX_LINK_USERS" Description="Идентификатор непрочитанной новости пользователем" PrimaryKey="NewsBoxLinkUsersID"><Fields><Attribute Name="NewsBoxLinkUsersID" Index="3480001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Users" Index="3480002" Type="VCLib.BASE_USERS" Description="Пользователь системы" Required="1"></Parent><Parent Name="NewsBox" Index="3480003" Type="VCLib.NEWS_BOX" Description="Новостная информация" Required="1"></Parent></Fields><DbMapping><Table name="T_NEWS_BOX_LINK_USERS"><Map Name="NewsBoxLinkUsersID" Column="NewsBoxLinkUsersID"></Map><Map Name="Users" Column="Users"></Map><Map Name="NewsBox" Column="NewsBox"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX_LINK_USERS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_BOX_USERS_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_BOX_USERS_GROUP',NULL,'Primary SQL Server','Связь новости с группой пользователей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Связь новости с группой пользователей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_BOX_USERS_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_BOX_USERS_GROUP" Description="Связь новости с группой пользователей" PrimaryKey="NewsBoxUsersGroupID"><Fields><Attribute Name="NewsBoxUsersGroupID" Index="460001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="UsersGroup" Index="460002" Type="VCLib.USERS_GROUP" Description="Группа пользователей" Required="1"></Parent><Parent Name="NewsBox" Index="460003" Type="VCLib.NEWS_BOX" Description="Новостная информация" Required="1"></Parent></Fields><DbMapping><Table name="T_NEWS_BOX_USERS_GROUP"><Map Name="NewsBoxUsersGroupID" Column="NewsBoxUsersGroupID"></Map><Map Name="UsersGroup" Column="UsersGroup"></Map><Map Name="NewsBox" Column="NewsBox"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_BOX_USERS_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='NEWS_LIST')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'NEWS_LIST',NULL,'Primary SQL Server','Новостной лист',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Новостной лист',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='NEWS_LIST'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="NEWS_LIST" Description="Новостной лист" PrimaryKey="NewsListID"><Fields><Attribute Name="NewsListID" Index="3520001" Type="guid" Description="Идентификатор"></Attribute></Fields><DbMapping></DbMapping><CalculatingAttributes></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='NEWS_LIST'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='JOB')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'JOB',NULL,'Primary SQL Server','Задание планировщика',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Задание планировщика',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='JOB'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="JOB" Description="Задание планировщика" PrimaryKey="JobID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="JobID" Index="630001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="630002" Type="string" Description="Наименование задания" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="ConcurrentExecute" Index="630003" Type="bool" Description="Параллельное исполнение" Required="1"></Attribute><Parent Name="JobUser" Index="630006" Type="VCLib.BASE_USERS" Description="Исполнение от имени"></Parent><Child Name="Steps" Index="630004" Type="VCLib.JOB_STEP" Description="Шаги исполнения" ChildAttribute="Job" SortingAttr="Step" Required="1"></Child><Child Name="Schedules" Index="630005" Type="VCLib.JOB_SCHEDULE" Description="Расписание" ChildAttribute="Job"></Child></Fields><DbMapping><Table name="T_JOB"><Map Name="JobID" Column="JobID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ConcurrentExecute" Column="ConcurrentExecute"></Map><Map Name="JobUser" Column="JobUser"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='JOB'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='JOB_SCHEDULE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'JOB_SCHEDULE',NULL,'Primary SQL Server','Расписание исполнения задания',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Расписание исполнения задания',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='JOB_SCHEDULE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="JOB_SCHEDULE" Description="Расписание исполнения задания" PrimaryKey="ScheduleID"><Fields><Attribute Name="ScheduleID" Index="650001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Mask" Index="650004" Type="int" Description="Маска"></Attribute><Attribute Name="StartDate" Index="650005" Type="date" Description="Начальная дата" Required="1"></Attribute><Attribute Name="EndDate" Index="650006" Type="date" Description="Конечная дата"></Attribute><Attribute Name="Recurs" Index="650008" Type="int" Description="Повтор"></Attribute><Attribute Name="StartTime" Index="650009" Type="datetime" Description="Время старта" DefaultFormat="{0:HH:mm}"></Attribute><Attribute Name="Enabled" Index="650010" Type="bool" Description="Активно" DefaultValue="1" Required="1"></Attribute><Parent Name="Job" Index="650002" Type="VCLib.JOB" Description="Задание планировщика" Required="1"></Parent><Parent Name="Servers" Index="650011" Type="VCLib.SERVERS" Description="Сервер"></Parent><Choice Name="Type" Index="650003" Description="Тип исполнения" Required="1"><Item Name="Старт сервера" Index="0"></Item><Item Name="Одноразово" Index="1"></Item><Item Name="Периодически" Index="2"></Item></Choice><Choice Name="Occurs" Index="650007" Description="Тип периодичности"><Item Name="Ежедневно" Index="0"></Item><Item Name="Еженедельно" Index="1"></Item><Item Name="Ежемесячно" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_JOB_SCHEDULE"><Map Name="ScheduleID" Column="ScheduleID"></Map><Map Name="Job" Column="Job"></Map><Map Name="Type" Column="Type"></Map><Map Name="Mask" Column="Mask"></Map><Map Name="StartDate" Column="StartDate"></Map><Map Name="EndDate" Column="EndDate"></Map><Map Name="Occurs" Column="Occurs"></Map><Map Name="Recurs" Column="Recurs"></Map><Map Name="StartTime" Column="StartTime"></Map><Map Name="Enabled" Column="Enabled"></Map><Map Name="Servers" Column="Servers"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='JOB_SCHEDULE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='JOB_STEP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'JOB_STEP',NULL,'Primary SQL Server','Шаг исполнения задания',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаг исполнения задания',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='JOB_STEP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="JOB_STEP" Description="Шаг исполнения задания" PrimaryKey="JobStepID" DNAttributes="{Operation}" DisplayName="{0}"><Fields><Attribute Name="JobStepID" Index="640001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Step" Index="640002" Type="int" Description="Номер шага" Required="1"></Attribute><Attribute Name="ContinueOnError" Index="640003" Type="bool" Description="Продолжать при ошибке"></Attribute><Parent Name="Job" Index="640004" Type="VCLib.JOB" Description="Задание планировщика" Required="1"></Parent><Parent Name="Operation" Index="640005" Type="VCLib.SCHEDULER_OPERATION" Description="Операция" Required="1"></Parent></Fields><DbMapping><Table name="T_JOB_STEP"><Map Name="JobStepID" Column="JobStepID"></Map><Map Name="Step" Column="Step"></Map><Map Name="ContinueOnError" Column="ContinueOnError"></Map><Map Name="Job" Column="Job"></Map><Map Name="Operation" Column="Operation"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='JOB_STEP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='JobExecutionError')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'JobExecutionError',NULL,'Primary SQL Server','Ошибка выполнения шага задания',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ошибка выполнения шага задания',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='JobExecutionError'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="JobExecutionError" Description="Ошибка выполнения шага задания" PrimaryKey="JobExecutionErrorID" DNAttributes="{DateTime};{Message}" DisplayName="{0} - {1}"><Fields><Attribute Name="JobExecutionErrorID" Index="680001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Message" Index="680002" Type="string" Description="Сообщение об ошибке" CharacterMaximumLength="4000"></Attribute><Attribute Name="Details" Index="680003" Type="text" Description="Подробная информация об ошибке"></Attribute><Attribute Name="DateTime" Index="680004" Type="datetime" Description="Дата и время" DefaultFormat="{0:dd.MM.yyyy HH:mm}"></Attribute><Parent Name="Step" Index="680005" Type="VCLib.JOB_STEP" Description="Шаг задания"></Parent></Fields><DbMapping><Table name="T_JobExecutionError"><Map Name="JobExecutionErrorID" Column="JobExecutionErrorID"></Map><Map Name="Message" Column="Message"></Map><Map Name="Details" Column="Details"></Map><Map Name="DateTime" Column="DateTime"></Map><Map Name="Step" Column="Step"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='JobExecutionError'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='RUN_PROCESS_OPERATION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'RUN_PROCESS_OPERATION',NULL,'Primary SQL Server','Запуск процесса',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Запуск процесса',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION') WHERE [Schema]='VCLib' and EntName='RUN_PROCESS_OPERATION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="RUN_PROCESS_OPERATION" Description="Запуск процесса" DNAttributes="{Name}" DisplayName="{0}" Inherits="VCLib.SCHEDULER_OPERATION"><Fields><Attribute Name="ProcessName" Index="660001" Type="string" Description="Имя процесса" CharacterMaximumLength="64" Required="1"></Attribute></Fields><DbMapping><Table name="T_SCHEDULER_OPERATION"><Map Name="ProcessName" Column="ProcessName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='RUN_PROCESS_OPERATION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SCHEDULER_OPERATION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SCHEDULER_OPERATION',NULL,'Primary SQL Server','Операция планировщика заданий',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Операция планировщика заданий',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SCHEDULER_OPERATION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SCHEDULER_OPERATION" Description="Операция планировщика заданий" PrimaryKey="OperationID"><Fields><Attribute Name="OperationID" Index="620001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="620002" Type="string" Description="Наименование операции" CharacterMaximumLength="255" Required="1"></Attribute></Fields><DbMapping><Table name="T_SCHEDULER_OPERATION"><Map Name="OperationID" Column="OperationID"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SCHEDULER_OPERATION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_COLUMN')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_COLUMN',NULL,'Primary SQL Server','Колонка экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Колонка экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXPORT_COLUMN'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_COLUMN" Description="Колонка экспорта" PrimaryKey="ExportColumnID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="ExportColumnID" Index="3700001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3700002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Description" Index="3700003" Type="string" Description="Описание"></Attribute><Attribute Name="Length" Index="3700005" Type="int" Description="Длина"></Attribute><Attribute Name="DecimalCount" Index="3700006" Type="int" Description="Точность"></Attribute><Attribute Name="AttributePath" Index="3700007" Type="text" Description="Путь до аттрибута"></Attribute><Attribute Name="OrderNum" Index="3700009" Type="int" Description="Порядок" Required="1"></Attribute><Parent Name="ExportTable" Index="3700008" Type="VCLib.EXPORT_TABLE" Description="Таблица экспорта" Required="1"></Parent><Choice Name="Type" Index="3700004" Description="Тип данных" Required="1"><Item Name="AnsiStringFixedLength" Index="0"></Item><Item Name="AnsiString" Index="1"></Item><Item Name="Decimal" Index="2"></Item><Item Name="Date" Index="3"></Item><Item Name="Boolean" Index="4"></Item><Item Name="Autoincrement" Index="5"></Item></Choice></Fields><DbMapping><Table name="T_EXPORT_COLUMN"><Map Name="ExportColumnID" Column="ExportColumnID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Description" Column="Description"></Map><Map Name="Type" Column="Type"></Map><Map Name="Length" Column="Length"></Map><Map Name="DecimalCount" Column="DecimalCount"></Map><Map Name="AttributePath" Column="AttributePath"></Map><Map Name="ExportTable" Column="ExportTable"></Map><Map Name="OrderNum" Column="OrderNum"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_COLUMN'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_DATA')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_DATA',NULL,'Primary SQL Server','Экспорт данных',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Экспорт данных',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXPORT_DATA'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_DATA" Description="Экспорт данных" PrimaryKey="ExportDataID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="ExportDataID" Index="3710001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3710002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Parameters" Index="3710006" Type="string" Description="Параметры" CharacterMaximumLength="1024"></Attribute><Attribute Name="IsOpen" Index="3710008" Type="bool" Description="Открыть после формирования" Required="1"></Attribute><Child Name="ExportTables" Index="3710005" Type="VCLib.EXPORT_TABLE" Description="Таблицы экспорта" ChildAttribute="ExportData"></Child><Child Name="ExportTemplates" Index="3710007" Type="VCLib.EXPORT_TEMPLATE" Description="Щаблоны экспорта" ChildAttribute="ExportData"></Child><Choice Name="ExportProvider" Index="3710003" Description="Поставщик" Required="1"><Item Name="DBF" Index="0"></Item><Item Name="CSV" Index="1"></Item><Item Name="Excel" Index="2"></Item><Item Name="Отчет" Index="10"></Item></Choice></Fields><DbMapping><Table name="T_EXPORT_DATA"><Map Name="ExportDataID" Column="ExportDataID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ExportProvider" Column="ExportProvider"></Map><Map Name="Parameters" Column="Parameters"></Map><Map Name="IsOpen" Column="IsOpen"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_DATA'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_TABLE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_TABLE',NULL,'Primary SQL Server','Таблица экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Таблица экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXPORT_TABLE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_TABLE" Description="Таблица экспорта" PrimaryKey="ExportTableID" DNAttributes="{Description}" DisplayName="{0}"><Fields><Attribute Name="ExportTableID" Index="3720001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3720002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Condition" Index="3720004" Type="text" Description="Фильтр"></Attribute><Attribute Name="Priority" Index="3720007" Type="int" Description="Приоритет" Required="1"></Attribute><Attribute Name="SortAttributes" Index="3720008" Type="text" Description="Атрибуты сортировки"></Attribute><Attribute Name="Description" Index="3720010" Type="string" Description="Описание"></Attribute><Attribute Name="GroupByPaths" Index="3720011" Type="text" Description="Атрибуты группировки"></Attribute><Attribute Name="FileNameAttrs" Index="3720012" Type="text" Description="Атрибуты наименования файла"></Attribute><Parent Name="ExportData" Index="3720003" Type="VCLib.EXPORT_DATA" Description="Экспорт данных" Required="1"></Parent><Parent Name="Entities" Index="3720005" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="ExportColumns" Index="3720006" Type="VCLib.EXPORT_COLUMN" Description="Колонки" ChildAttribute="ExportTable"></Child><Choice Name="Sort" Index="3720009" Description="Сортировка"><Item Name="По возрастанию" Index="0"></Item><Item Name="По убыванию" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_EXPORT_TABLE"><Map Name="ExportTableID" Column="ExportTableID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ExportData" Column="ExportData"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="SortAttributes" Column="SortAttributes"></Map><Map Name="Sort" Column="Sort"></Map><Map Name="Description" Column="Description"></Map><Map Name="GroupByPaths" Column="GroupByPaths"></Map><Map Name="FileNameAttrs" Column="FileNameAttrs"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_TABLE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_TEMPLATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_TEMPLATE',NULL,'Primary SQL Server','Щаблон экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Щаблон экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='EXPORT_TEMPLATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_TEMPLATE" Description="Щаблон экспорта" DNAttributes="{FileName}" DisplayName="{0}" Inherits="VCLib.FILES"><Fields><Attribute Name="OutputName" Index="490004" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="ReportFileFormat" Index="490001" Type="VCLib.ReportFileFormat" Description="Формат отчета" Required="1"></Parent><Parent Name="ExportData" Index="490002" Type="VCLib.EXPORT_DATA" Description="Экспорт данных" Required="1"></Parent><Choice Name="OutputFormat" Index="490003" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice><Choice Name="ProcessingWay" Index="490007" Description="Способ обработки" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_EXPORT_TEMPLATE"><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="ExportData" Column="ExportData"></Map><Map Name="ProcessingWay" Column="ProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_TEMPLATE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DEPENDENCY_MODIFICATION',NULL,'Primary SQL Server','Изменение зависимого объекта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Изменение зависимого объекта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DEPENDENCY_MODIFICATION" Description="Изменение зависимого объекта" PrimaryKey="DependencyModificationID"><Fields><Attribute Name="DependencyModificationID" Index="2070001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="InsertFilter" Index="2070003" Type="text" Description="Критерий выполнения(добавление)"></Attribute><Attribute Name="UpdateFilter" Index="2070004" Type="text" Description="Критерий выполнения(изменение)"></Attribute><Attribute Name="DeleteFilter" Index="2070005" Type="text" Description="Критерий выполнения(удаление)"></Attribute><Parent Name="DependencyModificationAction" Index="2070002" Type="VCLib.DEPENDENCY_MODIFICATION_ACTION" Description="Действие при изменении зависимостей"></Parent><Choice Name="EditType" Index="2070006" Description="Тип изменения" Required="1" IsFlag="1"><Item Name="Добавление" Index="2"></Item><Item Name="Изменение" Index="4"></Item><Item Name="Удаление" Index="8"></Item></Choice></Fields><DbMapping><Table name="T_DEPENDENCY_MODIFICATION"><Map Name="DependencyModificationID" Column="DependencyModificationID"></Map><Map Name="DependencyModificationAction" Column="DependencyModificationAction"></Map><Map Name="EditType" Column="EditType"></Map><Map Name="InsertFilter" Column="InsertFilter"></Map><Map Name="UpdateFilter" Column="UpdateFilter"></Map><Map Name="DeleteFilter" Column="DeleteFilter"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION_ACTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DEPENDENCY_MODIFICATION_ACTION',NULL,'Primary SQL Server','Действие при изменении зависимостей',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'OBJECT_MODIFICATION_ACTION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Действие при изменении зависимостей',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'OBJECT_MODIFICATION_ACTION') WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION_ACTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DEPENDENCY_MODIFICATION_ACTION" Description="Действие при изменении зависимостей" Inherits="VCLib.OBJECT_MODIFICATION_ACTION"><Fields><Child Name="DependencyModifications" Index="2060001" Type="VCLib.DEPENDENCY_MODIFICATION" Description="Изменения зависимых объекта" ChildAttribute="DependencyModificationAction"></Child></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='DEPENDENCY_MODIFICATION_ACTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'OBJECT_MODIFICATION_ACTION',NULL,'Primary SQL Server','Действие при изменении объекта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Действие при изменении объекта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="OBJECT_MODIFICATION_ACTION" Description="Действие при изменении объекта" PrimaryKey="ObjectModificationActionID"><Fields><Attribute Name="ObjectModificationActionID" Index="2050001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="StoredProcedure" Index="2050002" Type="string" Description="Наименование хранимой процедуры" Required="1"></Attribute><Attribute Name="Active" Index="2050006" Type="bool" Description="Активно" Required="1"></Attribute><Parent Name="Entities" Index="2050003" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="ObjectModificationActionParams" Index="2050004" Type="VCLib.OBJECT_MODIFICATION_ACTION_PARAM" Description="Параметры действия при изменении объекта" ChildAttribute="ObjectModificationAction"></Child><Choice Name="Position" Index="2050005" Description="Позиция" Required="1"><Item Name="До изменения" Index="0"></Item><Item Name="После изменения" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_OBJECT_MODIFICATION_ACTION"><Map Name="ObjectModificationActionID" Column="ObjectModificationActionID"></Map><Map Name="StoredProcedure" Column="StoredProcedure"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="Position" Column="Position"></Map><Map Name="Active" Column="Active"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION_PARAM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'OBJECT_MODIFICATION_ACTION_PARAM',NULL,'Primary SQL Server','Параметр действия при изменении объекта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр действия при изменении объекта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION_PARAM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="OBJECT_MODIFICATION_ACTION_PARAM" Description="Параметр действия при изменении объекта" PrimaryKey="ObjectModificationActionParamID"><Fields><Attribute Name="ObjectModificationActionParamID" Index="2040001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="2040003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="ParamValue" Index="2040004" Type="text" Description="Значение" Required="1"></Attribute><Parent Name="ObjectModificationAction" Index="2040002" Type="VCLib.OBJECT_MODIFICATION_ACTION" Description="Действие при изменении объекта" Required="1"></Parent></Fields><DbMapping><Table name="T_OBJECT_MODIFICATION_ACTION_PARAM"><Map Name="ObjectModificationActionParamID" Column="ObjectModificationActionParamID"></Map><Map Name="ObjectModificationAction" Column="ObjectModificationAction"></Map><Map Name="ParamValue" Column="ParamValue"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='OBJECT_MODIFICATION_ACTION_PARAM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SINGLE_MODIFICATION_ACTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SINGLE_MODIFICATION_ACTION',NULL,'Primary SQL Server','Действие при изменении текущего объекта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'OBJECT_MODIFICATION_ACTION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Действие при изменении текущего объекта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'OBJECT_MODIFICATION_ACTION') WHERE [Schema]='VCLib' and EntName='SINGLE_MODIFICATION_ACTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SINGLE_MODIFICATION_ACTION" Description="Действие при изменении текущего объекта" Inherits="VCLib.OBJECT_MODIFICATION_ACTION"><Fields><Attribute Name="InsertFilter" Index="2030007" Type="text" Description="Критерий выполнения(добавление)"></Attribute><Attribute Name="UpdateFilter" Index="2030008" Type="text" Description="Критерий выполнения(изменение)"></Attribute><Attribute Name="DeleteFilter" Index="2030009" Type="text" Description="Критерий выполнения(удаление)"></Attribute><Choice Name="EditType" Index="2030005" Description="Тип изменения" Required="1" IsFlag="1"><Item Name="Добавление" Index="2"></Item><Item Name="Изменение" Index="4"></Item><Item Name="Удаление" Index="8"></Item></Choice></Fields><DbMapping><Table name="T_SINGLE_MODIFICATION_ACTION"><Map Name="EditType" Column="EditType"></Map><Map Name="InsertFilter" Column="InsertFilter"></Map><Map Name="UpdateFilter" Column="UpdateFilter"></Map><Map Name="DeleteFilter" Column="DeleteFilter"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SINGLE_MODIFICATION_ACTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ImportLog')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ImportLog',NULL,'Primary SQL Server','Журнал импорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Журнал импорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ImportLog'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ImportLog" Description="Журнал импорта" version="2" PrimaryKey="ImportLogID" DNAttributes="{EntityID/EntDesc};{StopDate};{UserID/UserName}" DisplayName="{0} : {1} : {2}"><Fields><Attribute Name="ImportLogID" Index="960001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="StartDate" Index="960004" Type="datetime" Description="Время начала" DefaultFormat="{0:yyyy.MM.dd HH:mm:ss}" Required="1"></Attribute><Attribute Name="StopDate" Index="960005" Type="datetime" Description="Время завершения" DefaultFormat="{0:yyyy.MM.dd HH:mm:ss}" Required="1"></Attribute><Parent Name="EntityID" Index="960002" Type="VCLib.ENTITIES" Description="Сущность" Required="1"></Parent><Parent Name="UserID" Index="960003" Type="VCLib.BASE_USERS" Description="Пользователь" Required="1"></Parent><Child Name="Items" Index="960006" Type="VCLib.ImportLogItem" Description="Импортированные объекты" ChildAttribute="ImportLogID"></Child></Fields><DbMapping><Table name="T_IMPORTLOG"><Map Name="ImportLogID" Column="ImportLogID"></Map><Map Name="EntityID" Column="EntityID"></Map><Map Name="UserID" Column="UserID"></Map><Map Name="StartDate" Column="StartDate"></Map><Map Name="StopDate" Column="StopDate"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ImportLog'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ImportLogItem')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ImportLogItem',NULL,'Primary SQL Server','Импортированный объект',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Импортированный объект',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='ImportLogItem'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ImportLogItem" Description="Импортированный объект" version="2" PrimaryKey="ImportLogItemID"><Fields><Attribute Name="ImportLogItemID" Index="970001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="PrimaryKeyInt" Index="970004" Type="int" Description="Идентификатор объекта типа int"></Attribute><Attribute Name="PrimaryKeyGuid" Index="970005" Type="guid" Description="Идентификатор объекта типа guid"></Attribute><Attribute Name="DispName" Index="970006" Type="string" Description="DisplayName объекта"></Attribute><Parent Name="ImportLogID" Index="970002" Type="VCLib.ImportLog" Description="Пакетный импорт" Required="1"></Parent><Choice Name="Action" Index="970003" Description="Действие" Required="1"><Item Name="Добавление" Index="0"></Item><Item Name="Изменение" Index="1"></Item><Item Name="Удаление" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_IMPORTLOGITEM"><Map Name="ImportLogItemID" Column="ImportLogItemID"></Map><Map Name="ImportLogID" Column="ImportLogID"></Map><Map Name="Action" Column="Action"></Map><Map Name="PrimaryKeyInt" Column="PrimaryKeyInt"></Map><Map Name="PrimaryKeyGuid" Column="PrimaryKeyGuid"></Map><Map Name="DispName" Column="DispName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='ImportLogItem'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_ATTRIBUTE',NULL,'Primary SQL Server','Атрибут справочника',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Атрибут справочника',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_ATTRIBUTE" Description="Атрибут справочника" PrimaryKey="DictionaryAttributeID"><Fields><Attribute Name="DictionaryAttributeID" Index="550001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="550003" Type="string" Description="Наименование" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="AttrDescription" Index="550004" Type="string" Description="Описание аттрибута" CharacterMaximumLength="255" Required="1"></Attribute><Attribute Name="IsKey" Index="550005" Type="bool" Description="Ключевой атрибут" Required="1"></Attribute><Attribute Name="AttrLexem" Index="550006" Type="text" Description="Лексема атрибута"></Attribute><Attribute Name="IsChecked" Index="550007" Type="bool" Description="Отмечен" Required="1"></Attribute><Parent Name="DictionaryUpdate" Index="550002" Type="VCLib.DICTIONARY_UPDATE" Description="Обновляемый справочник" Required="1"></Parent><Child Name="DictionaryAttributeKeys" Index="550008" Type="VCLib.DICTIONARY_ATTRIBUTE_KEY" Description="Ключи атрибута справочника" ChildAttribute="DictionaryAttribute"></Child></Fields><DbMapping><Table name="T_DICTIONARY_ATTRIBUTE"><Map Name="DictionaryAttributeID" Column="DictionaryAttributeID"></Map><Map Name="DictionaryUpdate" Column="DictionaryUpdate"></Map><Map Name="Name" Column="Name"></Map><Map Name="AttrDescription" Column="AttrDescription"></Map><Map Name="IsKey" Column="IsKey"></Map><Map Name="AttrLexem" Column="AttrLexem"></Map><Map Name="IsChecked" Column="IsChecked"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE_KEY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_ATTRIBUTE_KEY',NULL,'Primary SQL Server','Ключ атрибута справочника',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ключ атрибута справочника',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE_KEY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_ATTRIBUTE_KEY" Description="Ключ атрибута справочника" PrimaryKey="DictionaryAttributeKeyID"><Fields><Attribute Name="DictionaryAttributeKeyID" Index="560001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="560003" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="KeyLexem" Index="560004" Type="text" Description="Лексема" Required="1"></Attribute><Attribute Name="IsChecked" Index="560005" Type="bool" Description="Активен" Required="1"></Attribute><Parent Name="DictionaryAttribute" Index="560002" Type="VCLib.DICTIONARY_ATTRIBUTE" Description="Атрибут справочника" Required="1"></Parent></Fields><DbMapping><Table name="T_DICTIONARY_ATTRIBUTE_KEY"><Map Name="DictionaryAttributeKeyID" Column="DictionaryAttributeKeyID"></Map><Map Name="DictionaryAttribute" Column="DictionaryAttribute"></Map><Map Name="Name" Column="Name"></Map><Map Name="KeyLexem" Column="KeyLexem"></Map><Map Name="IsChecked" Column="IsChecked"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_ATTRIBUTE_KEY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_DEPEND')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_DEPEND',NULL,'Primary SQL Server','Зависимость справочника',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Зависимость справочника',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_DEPEND'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_DEPEND" Description="Зависимость справочника" PrimaryKey="DictionaryDependID" DNAttributes="{DependedDictionary/Code}" DisplayName="{0}"><Fields><Attribute Name="DictionaryDependID" Index="2130001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="DictionaryUpdate" Index="2130002" Type="VCLib.DICTIONARY_UPDATE" Description="Обновляемый справочник" Required="1"></Parent><Parent Name="DependedDictionary" Index="2130003" Type="VCLib.DICTIONARY_UPDATE" Description="Зависит от справочника" Required="1"></Parent></Fields><DbMapping><Table name="T_DICTIONARY_DEPEND"><Map Name="DictionaryDependID" Column="DictionaryDependID"></Map><Map Name="DictionaryUpdate" Column="DictionaryUpdate"></Map><Map Name="DependedDictionary" Column="DependedDictionary"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_DEPEND'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_SCHEDULE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_SCHEDULE',NULL,'Primary SQL Server','Операция обновления справочника',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Операция обновления справочника',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION') WHERE [Schema]='VCLib' and EntName='DICTIONARY_SCHEDULE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_SCHEDULE" Description="Операция обновления справочника" Inherits="VCLib.SCHEDULER_OPERATION"><Fields><Attribute Name="LoadReferences" Index="540002" Type="bool" Description="Загружать зависимости" Required="1"></Attribute><Parent Name="DictionaryUpdateInfo" Index="540001" Type="VCLib.DICTIONARY_UPDATE_INFO" Description="Информация об обновлении справочников" Required="1"></Parent></Fields><DbMapping><Table name="T_DICTIONARY_SCHEDULE"><Map Name="DictionaryUpdateInfo" Column="DictionaryUpdateInfo"></Map><Map Name="LoadReferences" Column="LoadReferences"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_SCHEDULE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_SERVICE_LINK')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_SERVICE_LINK',NULL,'Primary SQL Server','Адрес сервера обновлений справочников',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Адрес сервера обновлений справочников',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_SERVICE_LINK'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_SERVICE_LINK" Description="Адрес сервера обновлений справочников" PrimaryKey="DictionaryServiceLinkID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="DictionaryServiceLinkID" Index="2150001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="2150003" Type="string" Description="Наименование источника" Required="1"></Attribute><Attribute Name="SourceAddres" Index="2150004" Type="string" Description="Адрес сервера обновления" Required="1"></Attribute><Attribute Name="UpdateKey" Index="2150005" Type="string" Description="Ключ обновления" CharacterMaximumLength="40"></Attribute></Fields><DbMapping><Table name="T_DICTIONARY_SERVICE_LINK"><Map Name="DictionaryServiceLinkID" Column="DictionaryServiceLinkID"></Map><Map Name="Name" Column="Name"></Map><Map Name="SourceAddres" Column="SourceAddres"></Map><Map Name="UpdateKey" Column="UpdateKey"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_SERVICE_LINK'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_UPDATE',NULL,'Primary SQL Server','Обновляемый справочник',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Обновляемый справочник',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_UPDATE" Description="Обновляемый справочник" PrimaryKey="DictionaryUpdateID"><Fields><Attribute Name="DictionaryUpdateID" Index="2100001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="IsVersion" Index="2100003" Type="bool" Description="Поддерживает версионность" Required="1"></Attribute><Attribute Name="DateUpdatePath" Index="2100004" Type="string" Description="Путь к аттрибуту с датой обновления" CharacterMaximumLength="1024"></Attribute><Attribute Name="Code" Index="2100006" Type="string" Description="Код справочника" Required="1"></Attribute><Attribute Name="LoadOrder" Index="2100008" Type="int" Description="Приоритет загрузки" Required="1"></Attribute><Attribute Name="Descr" Index="2100009" Type="string" Description="Описание" Required="1"></Attribute><Attribute Name="GroupByPaths" Index="2100013" Type="text" Description="Атрибуты группировки"></Attribute><Attribute Name="RecordsInPacket" Index="2100014" Type="int" Description="Количество записей в пакете"></Attribute><Parent Name="Entities" Index="2100002" Type="VCLib.ENTITIES" Description="Сущность справочник" Required="1"></Parent><Child Name="DictionaryUsers" Index="2100010" Type="VCLib.DICTIONARY_USER" Description="Получатели справочника" ChildAttribute="DictionaryUpdate"></Child><Child Name="DictionaryDepends" Index="2100011" Type="VCLib.DICTIONARY_DEPEND" Description="Зависимости от справочников" ChildAttribute="DictionaryUpdate"></Child><Child Name="DictionaryAttributes" Index="2100015" Type="VCLib.DICTIONARY_ATTRIBUTE" Description="Атрибут справочника" ChildAttribute="DictionaryUpdate"></Child></Fields><DbMapping><Table name="T_DICTIONARY_UPDATE"><Map Name="DictionaryUpdateID" Column="DictionaryUpdateID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="IsVersion" Column="IsVersion"></Map><Map Name="DateUpdatePath" Column="DateUpdatePath"></Map><Map Name="Code" Column="Code"></Map><Map Name="LoadOrder" Column="LoadOrder"></Map><Map Name="Descr" Column="Descr"></Map><Map Name="GroupByPaths" Column="GroupByPaths"></Map><Map Name="RecordsInPacket" Column="RecordsInPacket"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE_INFO')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_UPDATE_INFO',NULL,'Primary SQL Server','Информация об обновлении справочников',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Информация об обновлении справочников',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE_INFO'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_UPDATE_INFO" Description="Информация об обновлении справочников" PrimaryKey="DictionaryUpdateInfoID"><Fields><Attribute Name="DictionaryUpdateInfoID" Index="2140001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Code" Index="2140002" Type="string" Description="Код" Required="1"></Attribute><Attribute Name="LastUpdateDate" Index="2140003" Type="date" Description="Дата последней загрузки"></Attribute><Attribute Name="Source" Index="2140004" Type="string" Description="Источник обновления"></Attribute></Fields><DbMapping><Table name="T_DICTIONARY_UPDATE_INFO"><Map Name="DictionaryUpdateInfoID" Column="DictionaryUpdateInfoID"></Map><Map Name="Code" Column="Code"></Map><Map Name="LastUpdateDate" Column="LastUpdateDate"></Map><Map Name="Source" Column="Source"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_UPDATE_INFO'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='DICTIONARY_USER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'DICTIONARY_USER',NULL,'Primary SQL Server','Получатель справочника',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Получатель справочника',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='DICTIONARY_USER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="DICTIONARY_USER" Description="Получатель справочника" PrimaryKey="DictionaryUserID" DNAttributes="{ServiceUser/OrgName}" DisplayName="{0}"><Fields><Attribute Name="DictionaryUserID" Index="2120001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="DataFilter" Index="2120004" Type="text" Description="Фильтр"></Attribute><Attribute Name="UserDictionaryIndex" Index="2120005" Type="int" Description="Индекс сущности справочника получателя"></Attribute><Parent Name="DictionaryUpdate" Index="2120002" Type="VCLib.DICTIONARY_UPDATE" Description="Обновляемый справочник" Required="1"></Parent><Parent Name="ServiceUser" Index="2120003" Type="VCLib.SERVICE_USER" Description="Пользователь сервиса" Required="1"></Parent></Fields><DbMapping><Table name="T_DICTIONARY_USER"><Map Name="DictionaryUserID" Column="DictionaryUserID"></Map><Map Name="DictionaryUpdate" Column="DictionaryUpdate"></Map><Map Name="ServiceUser" Column="ServiceUser"></Map><Map Name="DataFilter" Column="DataFilter"></Map><Map Name="UserDictionaryIndex" Column="UserDictionaryIndex"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='DICTIONARY_USER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='SERVICE_USER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'SERVICE_USER',NULL,'Primary SQL Server','Пользователь сервиса',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Пользователь сервиса',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='SERVICE_USER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="SERVICE_USER" Description="Пользователь сервиса" PrimaryKey="ServiceUserID" DNAttributes="{OrgName}" DisplayName="{0}"><Fields><Attribute Name="ServiceUserID" Index="2110001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="OrgName" Index="2110002" Type="string" Description="Наименование организации" Required="1"></Attribute><Attribute Name="ServiceKey" Index="2110003" Type="string" Description="Ключ доступа" CharacterMaximumLength="40" Required="1"></Attribute></Fields><DbMapping><Table name="T_SERVICE_USER"><Map Name="ServiceUserID" Column="ServiceUserID"></Map><Map Name="OrgName" Column="OrgName"></Map><Map Name="ServiceKey" Column="ServiceKey"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='SERVICE_USER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERATOR_LINK')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERATOR_LINK',NULL,'Primary SQL Server','Ссылка на генератор',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на генератор',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERATOR_LINK'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERATOR_LINK" Description="Ссылка на генератор" PrimaryKey="GeneratorLinkID"><Fields><Attribute Name="GeneratorLinkID" Index="3190001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Link" Index="3190004" Description="Ссылка" Required="1"></Attribute><Attribute Name="Description" Index="3190005" Description="Описание"></Attribute><Attribute Name="GeneratorPath" Index="3190006" Type="string" Description="Путь до генератора" CharacterMaximumLength="1024"></Attribute><Parent Name="GenericReport" Index="3190002" Type="VCLib.GENERIC_REPORT" Description="Отчет" Required="1"></Parent><Parent Name="GrCommonGenerator" Index="3190003" Type="VCLib.GR_COMMON_GENERATOR" Description="Группировщик" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERATOR_LINK"><Map Name="GeneratorLinkID" Column="GeneratorLinkID"></Map><Map Name="GrCommonGenerator" Column="GrCommonGenerator"></Map><Map Name="GenericReport" Column="GenericReport"></Map><Map Name="Link" Column="Link"></Map><Map Name="Description" Column="Description"></Map><Map Name="GeneratorPath" Column="GeneratorPath"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="HRPath" Index="3190007" Type="string" Description="Путь" RequiredAttributes="{GeneratorPath};{GenericReport/Entities/EntityID}"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='GENERATOR_LINK'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERATOR_PARAMS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERATOR_PARAMS',NULL,'Primary SQL Server','Параметры генератора',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметры генератора',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERATOR_PARAMS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERATOR_PARAMS" Description="Параметры генератора" PrimaryKey="GeneratorParamsID"><Fields><Attribute Name="GeneratorParamsID" Index="3030001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3030002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Value" Index="3030003" Type="string" Description="Значение" Required="1"></Attribute><Attribute Name="MakeUser" Index="3030005" Type="bool" Description="Созданно пользователем" Required="1"></Attribute><Parent Name="GenericReport" Index="3030004" Type="VCLib.GENERIC_REPORT" Description="Обобщенная сущность для отчетов" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERATOR_PARAMS"><Map Name="GeneratorParamsID" Column="GeneratorParamsID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Value" Column="Value"></Map><Map Name="GenericReport" Column="GenericReport"></Map><Map Name="MakeUser" Column="MakeUser"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERATOR_PARAMS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT',NULL,'Primary SQL Server','Обобщенная сущность для отчетов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Обобщенная сущность для отчетов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT" Description="Обобщенная сущность для отчетов" PrimaryKey="GenericReportID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="GenericReportID" Index="3040004" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3040005" Type="string" Description="Наименование" CharacterMaximumLength="128" Required="1"></Attribute><Attribute Name="Filter" Index="3040012" Type="text" Description="Фильтр"></Attribute><Attribute Name="UseCustomGenerator" Index="3040015" Type="bool" Description="Использование специализированного генератора" Required="1"></Attribute><Parent Name="Entities" Index="3040009" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent><Child Name="GeneratorParams" Index="3040011" Type="VCLib.GENERATOR_PARAMS" Description="Параметры генератора" ChildAttribute="GenericReport"></Child><Child Name="GeneratorLinks" Index="3040016" Type="VCLib.GENERATOR_LINK" Description="Используемые генераторы" ChildAttribute="GenericReport"></Child><Child Name="GenericReportFunctions" Index="3040017" Type="VCLib.GENERIC_REPORT_FUNCTION" Description="Функции" ChildAttribute="GenericReport"></Child></Fields><DbMapping><Table name="T_GENERIC_REPORT"><Map Name="GenericReportID" Column="GenericReportID"></Map><Map Name="Entities" Column="Entities"></Map><Map Name="Filter" Column="Filter"></Map><Map Name="Name" Column="Name"></Map><Map Name="UseCustomGenerator" Column="UseCustomGenerator"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_FILE',NULL,'Primary SQL Server','Отчет из файла',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отчет из файла',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILE') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_FILE" Description="Отчет из файла" DNAttributes="{Name}" DisplayName="{0}" Inherits="VCLib.FILE"><Fields><Child Name="GenericReportFileRightss" Index="3560001" Type="VCLib.GENERIC_REPORT_FILE_RIGHTS" Description="Права на меню Отчеты" ChildAttribute="GenericReportFile"></Child></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE_RIGHTS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_FILE_RIGHTS',NULL,'Primary SQL Server','Права на меню Отчеты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Права на меню Отчеты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE_RIGHTS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_FILE_RIGHTS" Description="Права на меню Отчеты" PrimaryKey="ReportMenuItemRightsID"><Fields><Attribute Name="ReportMenuItemRightsID" Index="3550001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="GenericReportFile" Index="3550002" Type="VCLib.GENERIC_REPORT_FILE" Description="Отчет из файла" Required="1"></Parent><Parent Name="Roles" Index="3550003" Type="VCLib.ROLES" Description="Роли пользователей в системе" Required="1"></Parent><Choice Name="ReportRights" Index="3550004" Description="Разрешения" Required="1"><Item Name="Редактирование и генерация отчета" Index="0"></Item><Item Name="Генерация отчета" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_GENERIC_REPORT_FILE_RIGHTS"><Map Name="ReportMenuItemRightsID" Column="ReportMenuItemRightsID"></Map><Map Name="GenericReportFile" Column="GenericReportFile"></Map><Map Name="Roles" Column="Roles"></Map><Map Name="ReportRights" Column="ReportRights"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FILE_RIGHTS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FOR_USER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_FOR_USER',NULL,'Primary SQL Server','Пользовательский отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_MAIN'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Пользовательский отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_MAIN') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FOR_USER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_FOR_USER" Description="Пользовательский отчет" Inherits="VCLib.GENERIC_REPORT_MAIN"><Fields></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FOR_USER'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FUNCTION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_FUNCTION',NULL,'Primary SQL Server','Функция генератора отчетов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Функция генератора отчетов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FUNCTION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_FUNCTION" Description="Функция генератора отчетов" PrimaryKey="GenericReportFunctionID" DNAttributes="{Target};{Description}" DisplayName="{0}; {1}"><Fields><Attribute Name="GenericReportFunctionID" Index="3210001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Target" Index="3210002" Type="string" Description="Место назначения" CharacterMaximumLength="1024" Required="1"></Attribute><Attribute Name="Description" Index="3210003" Type="string" Description="Описание" CharacterMaximumLength="512"></Attribute><Attribute Name="Function" Index="3210004" Type="text" Description="Функция" Required="1"></Attribute><Attribute Name="Condition" Index="3210006" Type="text" Description="Условие"></Attribute><Attribute Name="Priority" Index="3210007" Type="int" Description="Приоритет" Required="1"></Attribute><Parent Name="GenericReport" Index="3210005" Type="VCLib.GENERIC_REPORT" Description="Обобщенная сущность для отчетов" Required="1"></Parent><Choice Name="Action" Index="3210008" Description="Действие" Required="1"><Item Name="Замена значения" Index="0"></Item><Item Name="Сложить" Index="1"></Item><Item Name="Вычесть" Index="2"></Item><Item Name="Умножить" Index="3"></Item><Item Name="Делить" Index="4"></Item></Choice></Fields><DbMapping><Table name="T_GENERIC_REPORT_FUNCTION"><Map Name="GenericReportFunctionID" Column="GenericReportFunctionID"></Map><Map Name="Target" Column="Target"></Map><Map Name="Description" Column="Description"></Map><Map Name="Function" Column="Function"></Map><Map Name="GenericReport" Column="GenericReport"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="Priority" Column="Priority"></Map><Map Name="Action" Column="Action"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_FUNCTION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GENERATOR')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_GENERATOR',NULL,'Primary SQL Server','Справочник генераторов',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Справочник генераторов',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GENERATOR'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_GENERATOR" Description="Справочник генераторов" PrimaryKey="GenericReportGeneratorID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="GenericReportGeneratorID" Index="3060001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3060002" Type="string" Description="Наименование" Required="1"></Attribute><Parent Name="Entities" Index="3060006" Type="VCLib.ENTITIES" Description="Сущность метаданных" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERIC_REPORT_GENERATOR"><Map Name="GenericReportGeneratorID" Column="GenericReportGeneratorID"></Map><Map Name="Name" Column="Name"></Map><Map Name="Entities" Column="Entities"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GENERATOR'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUP')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_GROUP',NULL,'Primary SQL Server','Группа отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группа отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUP'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_GROUP" Description="Группа отчета" PrimaryKey="GenericReportGroupID"><Fields><Attribute Name="GenericReportGroupID" Index="3180001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="OrderNum" Index="3180003" Type="string" Description="Порядковый номер" CharacterMaximumLength="64"></Attribute><Attribute Name="Name" Index="3180004" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="Link" Index="3180005" Description="Ссылка" Required="1"></Attribute><Parent Name="GrCommonGenerator" Index="3180002" Type="VCLib.GR_COMMON_GENERATOR" Description="Группировщик" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERIC_REPORT_GROUP"><Map Name="GenericReportGroupID" Column="GenericReportGroupID"></Map><Map Name="GrCommonGenerator" Column="GrCommonGenerator"></Map><Map Name="OrderNum" Column="OrderNum"></Map><Map Name="Name" Column="Name"></Map><Map Name="Link" Column="Link"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUP'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUPBY')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_GROUPBY',NULL,'Primary SQL Server','Группа по атрибутам',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GROUP'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группа по атрибутам',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GROUP') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUPBY'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_GROUPBY" Description="Группа по атрибутам" Inherits="VCLib.GENERIC_REPORT_GROUP"><Fields><Attribute Name="GroupByPaths" Index="3070003" Type="text" Description="Путь группировки" Required="1"></Attribute><Attribute Name="DisplayFormat" Index="3070007" Type="string" Description="Формат вывода" CharacterMaximumLength="512" Required="1"></Attribute><Choice Name="OrderBy" Index="3070004" Description="Направление сортировки" Required="1"><Item Name="По возрастанию" Index="0"></Item><Item Name="По убыванию" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_GENERIC_REPORT_GROUPBY"><Map Name="OrderBy" Column="OrderBy"></Map><Map Name="GroupByPaths" Column="GroupByPaths"></Map><Map Name="DisplayFormat" Column="DisplayFormat"></Map></Table></DbMapping><CalculatingAttributes><Attribute Name="HRPath" Index="3070006" Type="string" Description="Путь группировки в читабельном виде" RequiredAttributes="{GroupByPaths}"></Attribute></CalculatingAttributes></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_GROUPBY'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_MAIN',NULL,'Primary SQL Server','Составной отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Составной отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_MAIN" Description="Составной отчет" PrimaryKey="GenericReportMainID" DNAttributes="{Name}" DisplayName="{0}"><Fields><Attribute Name="GenericReportMainID" Index="3150001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="3150002" Type="string" Description="Наименование" CharacterMaximumLength="128" Required="1"></Attribute><Child Name="GenericReportTemplates" Index="3150003" Type="VCLib.GENERIC_REPORT_TEMPLATE" Description="Файл отчета" ChildAttribute="GenericReportMain"></Child><Child Name="GenericReportRights" Index="3150004" Type="VCLib.GENERIC_REPORT_RIGHTS" Description="Права на отчет" ChildAttribute="GenericReportMain" Required="1"></Child><Child Name="GenericReportMainItems" Index="3150005" Type="VCLib.GENERIC_REPORT_MAIN_ITEM" Description="Вложенные отчеты" ChildAttribute="GenericReportMain"></Child></Fields><DbMapping><Table name="T_GENERIC_REPORT_MAIN"><Map Name="GenericReportMainID" Column="GenericReportMainID"></Map><Map Name="Name" Column="Name"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_MAIN_ITEM',NULL,'Primary SQL Server','Вложенный отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Вложенный отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_MAIN_ITEM" Description="Вложенный отчет" PrimaryKey="GenericReportMainItemID"><Fields><Attribute Name="GenericReportMainItemID" Index="3160001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Condition" Index="3160004" Type="text" Description="Фильтр"></Attribute><Attribute Name="LinkName" Index="3160005" Type="string" Description="Ссылка" CharacterMaximumLength="32" Required="1"></Attribute><Attribute Name="Sorting" Index="3160006" Type="text" Description="Сортровка"></Attribute><Attribute Name="Descending" Index="3160007" Type="int" Description="Направление сортировки"></Attribute><Parent Name="GenericReportMain" Index="3160002" Type="VCLib.GENERIC_REPORT_MAIN" Description="Составной отчет" Required="1"></Parent><Parent Name="GenericReport" Index="3160003" Type="VCLib.GENERIC_REPORT" Description="Обобщенная сущность для отчетов" Required="1"></Parent></Fields><DbMapping><Table name="T_GENERIC_REPORT_MAIN_ITEM"><Map Name="GenericReportMain" Column="GenericReportMain"></Map><Map Name="GenericReport" Column="GenericReport"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="LinkName" Column="LinkName"></Map><Map Name="GenericReportMainItemID" Column="GenericReportMainItemID"></Map><Map Name="Sorting" Column="Sorting"></Map><Map Name="Descending" Column="Descending"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_MAIN_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_RIGHTS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_RIGHTS',NULL,'Primary SQL Server','Право на отчет',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Право на отчет',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_RIGHTS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_RIGHTS" Description="Право на отчет" PrimaryKey="GenericReportRightsID" DNAttributes="{Roles / DisplayName};{ReportRights}" DisplayName="{0} ({1})"><Fields><Attribute Name="GenericReportRightsID" Index="3080001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="GenericReportMain" Index="3080002" Type="VCLib.GENERIC_REPORT_MAIN" Description="Составной отчет" Required="1"></Parent><Parent Name="Roles" Index="3080003" Type="VCLib.ROLES" Description="Роли пользователей в системе" Required="1"></Parent><Choice Name="ReportRights" Index="3080004" Description="Разрешения" Required="1"><Item Name="Редактирование и генерация отчета" Index="0"></Item><Item Name="Генерация отчета" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_GENERIC_REPORT_RIGHTS"><Map Name="GenericReportRightsID" Column="GenericReportRightsID"></Map><Map Name="GenericReportMain" Column="GenericReportMain"></Map><Map Name="Roles" Column="Roles"></Map><Map Name="ReportRights" Column="ReportRights"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_RIGHTS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_TEMPLATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_TEMPLATE',NULL,'Primary SQL Server','Файл отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Файл отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_TEMPLATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_TEMPLATE" Description="Файл отчета" DNAttributes="{FileName}" DisplayName="{0}" Inherits="VCLib.FILES"><Fields><Attribute Name="OutputName" Index="3090004" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="ReportFileFormat" Index="3090001" Type="VCLib.ReportFileFormat" Description="Формат отчета" Required="1"></Parent><Parent Name="GenericReportMain" Index="3090002" Type="VCLib.GENERIC_REPORT_MAIN" Description="Составной отчет" Required="1"></Parent><Choice Name="OutputFormat" Index="3090003" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice><Choice Name="ProcessingWay" Index="8570007" Description="Способ обработки" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_GENERIC_REPORT_TEMPLATE"><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="GenericReportMain" Column="GenericReportMain"></Map><Map Name="ProcessingWay" Column="ProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_TEMPLATE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GR_COMMON_GENERATOR')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GR_COMMON_GENERATOR',NULL,'Primary SQL Server','Группировщик',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GENERATOR'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Группировщик',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GENERATOR') WHERE [Schema]='VCLib' and EntName='GR_COMMON_GENERATOR'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GR_COMMON_GENERATOR" Description="Группировщик" Inherits="VCLib.GENERIC_REPORT_GENERATOR"><Fields><Child Name="GenericReportGroups" Index="3110001" Type="VCLib.GENERIC_REPORT_GROUP" Description="Группа отчета" ChildAttribute="GrCommonGenerator"></Child></Fields></Entity>' WHERE [Schema]='VCLib' and EntName='GR_COMMON_GENERATOR'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='STATIC_GROUPS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'STATIC_GROUPS',NULL,'Primary SQL Server','Статическая группа',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GROUP'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Статическая группа',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'GENERIC_REPORT_GROUP') WHERE [Schema]='VCLib' and EntName='STATIC_GROUPS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="STATIC_GROUPS" Description="Статическая группа" Inherits="VCLib.GENERIC_REPORT_GROUP"><Fields><Attribute Name="Condition" Index="3140002" Type="text" Description="Фильтр"></Attribute><Attribute Name="ValueCondition" Index="3140004" Type="text" Description="Значение"></Attribute><Attribute Name="GroupCondition" Index="3140005" Type="text" Description="Условие на группу"></Attribute><Choice Name="MathType" Index="3140003" Description="Тип вычисления" Required="1"><Item Name="По количеству" Index="0"></Item><Item Name="По значению" Index="1"></Item><Item Name="По группе значений" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_STATIC_GROUPS"><Map Name="Condition" Column="Condition"></Map><Map Name="MathType" Column="MathType"></Map><Map Name="ValueCondition" Column="ValueCondition"></Map><Map Name="GroupCondition" Column="GroupCondition"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='STATIC_GROUPS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CONTACT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CONTACT',NULL,'Primary SQL Server','Контакт',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Контакт',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CONTACT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CONTACT" Description="Контакт" PrimaryKey="ContactID" DNAttributes="{LastName};{FirstName};{Position}" DisplayName="{0} {1} ({2})"><Fields><Attribute Name="ContactID" Index="3400001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="LastName" Index="3400002" Type="string" Description="Фамилия" Required="1"></Attribute><Attribute Name="FirstName" Index="3400003" Type="string" Description="Имя" Required="1"></Attribute><Attribute Name="FatherName" Index="3400004" Type="string" Description="Отчество"></Attribute><Attribute Name="Position" Index="3400005" Type="string" Description="Должность"></Attribute><Attribute Name="Phone" Index="3400007" Type="string" Description="Телефон"></Attribute><Child Name="EmailAddresss" Index="3400008" Type="VCLib.EMAIL_ADDRESS" Description="Адрес электронной почты" ChildAttribute="Contact" Required="1"></Child></Fields><DbMapping><Table name="T_CONTACT"><Map Name="ContactID" Column="ContactID"></Map><Map Name="LastName" Column="LastName"></Map><Map Name="FirstName" Column="FirstName"></Map><Map Name="FatherName" Column="FatherName"></Map><Map Name="Position" Column="Position"></Map><Map Name="Phone" Column="Phone"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='CONTACT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EMAIL_ADDRESS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EMAIL_ADDRESS',NULL,'Primary SQL Server','Адрес электронной почты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Адрес электронной почты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EMAIL_ADDRESS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EMAIL_ADDRESS" Description="Адрес электронной почты" PrimaryKey="EmailAddressID" DNAttributes="{EMail}" DisplayName="{0}"><Fields><Attribute Name="EmailAddressID" Index="3340001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="EMail" Index="3340002" Type="string" Description="Адрес электронной почты" Required="1"></Attribute><Parent Name="Contact" Index="3340003" Type="VCLib.CONTACT" Description="Контакт" Required="1"></Parent></Fields><DbMapping><Table name="T_EMAIL_ADDRESS"><Map Name="EmailAddressID" Column="EmailAddressID"></Map><Map Name="EMail" Column="EMail"></Map><Map Name="Contact" Column="Contact"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EMAIL_ADDRESS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EMAIL_ATTACHMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EMAIL_ATTACHMENT',NULL,'Primary SQL Server','Вложение сообщения электронной почты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Вложение сообщения электронной почты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EMAIL_ATTACHMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EMAIL_ATTACHMENT" Description="Вложение сообщения электронной почты" PrimaryKey="EmailAttachmentID"><Fields><Attribute Name="EmailAttachmentID" Index="3360001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="EmailMessage" Index="3360002" Type="VCLib.EMAIL_MESSAGE" Description="Сообщение электронной почты" Required="1"></Parent></Fields><DbMapping><Table name="T_EMAIL_ATTACHMENT"><Map Name="EmailAttachmentID" Column="EmailAttachmentID"></Map><Map Name="EmailMessage" Column="EmailMessage"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EMAIL_ATTACHMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EMAIL_MESSAGE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EMAIL_MESSAGE',NULL,'Primary SQL Server','Сообщение электронной почты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Сообщение электронной почты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION') WHERE [Schema]='VCLib' and EntName='EMAIL_MESSAGE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EMAIL_MESSAGE" Description="Сообщение электронной почты" Inherits="VCLib.SCHEDULER_OPERATION"><Fields><Attribute Name="Subject" Index="3330001" Type="string" Description="Тема"></Attribute><Attribute Name="Body" Index="3330002" Type="string" Description="Тело сообщения"></Attribute><Attribute Name="IsPack" Index="3330005" Type="bool" Description="Архивировать вложенные файлы" Required="1"></Attribute><Attribute Name="Password" Index="3330006" Type="string" Description="Пароль на архив"></Attribute><Child Name="EmailAttachments" Index="3330003" Type="VCLib.EMAIL_ATTACHMENT" Description="Вложение сообщения электронной почты" ChildAttribute="EmailMessage"></Child><Child Name="EmailRecipients" Index="3330004" Type="VCLib.EMAIL_RECIPIENT" Description="Получатель сообщения электронной почты" ChildAttribute="EmailMessage" Required="1"></Child><Child Name="ExportMessages" Index="3330007" Type="VCLib.EXPORT_MESSAGE" Description="Данные экспорта" ChildAttribute="EmailMessage"></Child></Fields><DbMapping><Table name="T_EMAIL_MESSAGE"><Map Name="Subject" Column="Subject"></Map><Map Name="Body" Column="Body"></Map><Map Name="IsPack" Column="IsPack"></Map><Map Name="Password" Column="Password"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EMAIL_MESSAGE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EMAIL_RECIPIENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EMAIL_RECIPIENT',NULL,'Primary SQL Server','Получатель сообщения электронной почты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Получатель сообщения электронной почты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EMAIL_RECIPIENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EMAIL_RECIPIENT" Description="Получатель сообщения электронной почты" PrimaryKey="EmailRecipientID"><Fields><Attribute Name="EmailRecipientID" Index="3350001" Type="guid" Description="Идентификатор"></Attribute><Parent Name="Contact" Index="3350002" Type="VCLib.CONTACT" Description="Контакт" Required="1"></Parent><Parent Name="EmailMessage" Index="3350003" Type="VCLib.EMAIL_MESSAGE" Description="Сообщение электронной почты" Required="1"></Parent></Fields><DbMapping><Table name="T_EMAIL_RECIPIENT"><Map Name="EmailRecipientID" Column="EmailRecipientID"></Map><Map Name="Contact" Column="Contact"></Map><Map Name="EmailMessage" Column="EmailMessage"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EMAIL_RECIPIENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_ITEM',NULL,'Primary SQL Server','Элемент экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Элемент экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXPORT_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_ITEM" Description="Элемент экспорта" PrimaryKey="ExportItemID"><Fields><Attribute Name="ExportItemID" Index="360001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Condition" Index="360004" Type="text" Description="Условие выгрузки"></Attribute><Parent Name="ExportMessage" Index="360003" Type="VCLib.EXPORT_MESSAGE" Description="Данные экспорта"></Parent><Parent Name="ExportTable" Index="360005" Type="VCLib.EXPORT_TABLE" Description="Таблица экспорта"></Parent></Fields><DbMapping><Table name="T_EXPORT_ITEM"><Map Name="ExportItemID" Column="ExportItemID"></Map><Map Name="ExportMessage" Column="ExportMessage"></Map><Map Name="Condition" Column="Condition"></Map><Map Name="ExportTable" Column="ExportTable"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_MESSAGE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_MESSAGE',NULL,'Primary SQL Server','Данные экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Данные экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXPORT_MESSAGE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_MESSAGE" Description="Данные экспорта" PrimaryKey="ExportMessageID"><Fields><Attribute Name="ExportMessageID" Index="350002" Type="guid" Description="Идентификатор"></Attribute><Parent Name="ExportOperation" Index="350001" Type="VCLib.EXPORT_OPERATION" Description="Операция экспорта"></Parent><Parent Name="EmailMessage" Index="350003" Type="VCLib.EMAIL_MESSAGE" Description="Сообщение электронной почты"></Parent><Parent Name="ExportData" Index="350005" Type="VCLib.EXPORT_DATA" Description="Экспорт данных"></Parent><Child Name="ExportItems" Index="350004" Type="VCLib.EXPORT_ITEM" Description="Элемент экспорта" ChildAttribute="ExportMessage"></Child></Fields><DbMapping><Table name="T_EXPORT_MESSAGE"><Map Name="ExportOperation" Column="ExportOperation"></Map><Map Name="ExportMessageID" Column="ExportMessageID"></Map><Map Name="EmailMessage" Column="EmailMessage"></Map><Map Name="ExportData" Column="ExportData"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_MESSAGE'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXPORT_OPERATION')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXPORT_OPERATION',NULL,'Primary SQL Server','Операция экспорта',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Операция экспорта',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'SCHEDULER_OPERATION') WHERE [Schema]='VCLib' and EntName='EXPORT_OPERATION'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXPORT_OPERATION" Description="Операция экспорта" Inherits="VCLib.SCHEDULER_OPERATION"><Fields><Attribute Name="IsPack" Index="370005" Type="bool" Description="Архивировать вложенные файлы" Required="1"></Attribute><Attribute Name="Password" Index="370006" Type="string" Description="Пароль на архив"></Attribute><Attribute Name="Path" Index="370007" Type="string" Description="Путь к папке на сервере" Required="1"></Attribute><Child Name="ExportMessages" Index="370002" Type="VCLib.EXPORT_MESSAGE" Description="Данные экспорта" ChildAttribute="ExportOperation"></Child></Fields><DbMapping><Table name="T_EXPORT_OPERATION"><Map Name="IsPack" Column="IsPack"></Map><Map Name="Password" Column="Password"></Map><Map Name="Path" Column="Path"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXPORT_OPERATION'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_ATTACHMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GENERIC_REPORT_ATTACHMENT',NULL,'Primary SQL Server','Вложения обобщенного отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'EMAIL_ATTACHMENT'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Вложения обобщенного отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'EMAIL_ATTACHMENT') WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_ATTACHMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GENERIC_REPORT_ATTACHMENT" Description="Вложения обобщенного отчета" DNAttributes="{GenericReportMain/Name}" DisplayName="{0}" Inherits="VCLib.EMAIL_ATTACHMENT"><Fields><Parent Name="GenericReportMain" Index="3380001" Type="VCLib.GENERIC_REPORT_MAIN" Description="Генератор отчетов" Required="1"></Parent><Child Name="GrAttachmentItems" Index="3380002" Type="VCLib.GR_ATTACHMENT_ITEM" Description="Вложенные отчеты" ChildAttribute="GenericReportAttachment"></Child></Fields><DbMapping><Table name="T_GENERIC_REPORT_ATTACHMENT"><Map Name="GenericReportMain" Column="GenericReportMain"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GENERIC_REPORT_ATTACHMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='GR_ATTACHMENT_ITEM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'GR_ATTACHMENT_ITEM',NULL,'Primary SQL Server','Ссылка на вложенный отчет в прикрепленном генераторе отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Ссылка на вложенный отчет в прикрепленном генераторе отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='GR_ATTACHMENT_ITEM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="GR_ATTACHMENT_ITEM" Description="Ссылка на вложенный отчет в прикрепленном генераторе отчета" PrimaryKey="GrAttachmentItemID"><Fields><Attribute Name="GrAttachmentItemID" Index="3390001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Condition" Index="3390004" Type="text" Description="Условие отчета"></Attribute><Parent Name="GenericReportMainItem" Index="3390002" Type="VCLib.GENERIC_REPORT_MAIN_ITEM" Description="Вложенный отчет" Required="1"></Parent><Parent Name="GenericReportAttachment" Index="3390003" Type="VCLib.GENERIC_REPORT_ATTACHMENT" Description="Вложенный генератор отчета" Required="1"></Parent></Fields><DbMapping><Table name="T_GR_ATTACHMENT_ITEM"><Map Name="GrAttachmentItemID" Column="GrAttachmentItemID"></Map><Map Name="GenericReportMainItem" Column="GenericReportMainItem"></Map><Map Name="GenericReportAttachment" Column="GenericReportAttachment"></Map><Map Name="Condition" Column="Condition"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='GR_ATTACHMENT_ITEM'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='REPORT_ATTACHMENT')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REPORT_ATTACHMENT',NULL,'Primary SQL Server','Отчет - вложение к сообщению электронной почты',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'EMAIL_ATTACHMENT'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Отчет - вложение к сообщению электронной почты',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'EMAIL_ATTACHMENT') WHERE [Schema]='VCLib' and EntName='REPORT_ATTACHMENT'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="REPORT_ATTACHMENT" Description="Отчет - вложение к сообщению электронной почты" DNAttributes="{Report/RepName}" DisplayName="{0}" Inherits="VCLib.EMAIL_ATTACHMENT"><Fields><Attribute Name="Condition" Index="3370002" Type="text" Description="Условие отчета"></Attribute><Parent Name="Report" Index="3370001" Type="VCLib.Report" Description="Отчет" Required="1"></Parent></Fields><DbMapping><Table name="T_REPORT_ATTACHMENT"><Map Name="Report" Column="Report"></Map><Map Name="Condition" Column="Condition"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='REPORT_ATTACHMENT'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='CREDENTIALS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'CREDENTIALS',NULL,'Primary SQL Server','Информация об учетной записи',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Информация об учетной записи',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='CREDENTIALS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="CREDENTIALS" Description="Информация об учетной записи" PrimaryKey="CredentialsID"><Fields><Attribute Name="CredentialsID" Index="430001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="CredentialDescription" Index="430005" Description="Описание"></Attribute><Attribute Name="ObjectUrl" Index="430007" Type="string" Description="Адрес объекта сервера" Required="1"></Attribute><Attribute Name="ServerName" Index="430008" Type="string" Description="Имя сервера" Required="1"></Attribute><Attribute Name="ServerID" Index="430009" Type="string" Description="Идентификатор сервера" CharacterMaximumLength="127" Required="1"></Attribute><Attribute Name="Login" Index="430010" Type="string" Description="Логин" Required="1"></Attribute><Attribute Name="Password" Index="430012" Type="string" Description="Пароль" CharacterMaximumLength="1000" Required="1"></Attribute><Choice Name="AuthenticationType" Index="430011" Description="Проверка подлинности" Required="1"><Item Name="Системная аутентификация" Index="0"></Item><Item Name="Windows аутентификация" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_CREDENTIALS"><Map Name="ServerName" Column="ServerName"></Map><Map Name="CredentialsID" Column="CredentialsID"></Map><Map Name="CredentialDescription" Column="CredentialDescription"></Map><Map Name="ObjectUrl" Column="ObjectUrl"></Map><Map Name="ServerID" Column="ServerID"></Map><Map Name="Login" Column="Login"></Map><Map Name="AuthenticationType" Column="AuthenticationType"></Map><Map Name="Password" Column="Password"></Map></Table></DbMapping><Customs><Custom Name="NotDisplayedColumns" Value="Password"></Custom><Custom Name="NotDisplayedInFilter" Value="Password"></Custom><Custom Name="NotTrackedAttributes" Value="Password"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='CREDENTIALS'
        GO
      
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='REMOTE_SERVER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REMOTE_SERVER',NULL,'Primary SQL Server','Удаленный сервер',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Удаленный сервер',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='REMOTE_SERVER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="REMOTE_SERVER" Description="Удаленный сервер" PrimaryKey="RemoteServerID"><Fields><Attribute Name="RemoteServerID" Index="420001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="420002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="ObjectUrl" Index="420003" Type="string" Description="Адрес объекта сервера" Required="1"></Attribute><Attribute Name="ServerID" Index="420006" Type="string" Description="Идентификатор сервера" CharacterMaximumLength="127" Required="1"></Attribute><Choice Name="AuthenticationType" Index="420005" Description="Проверка подлинности" Required="1"><Item Name="Системная аутентификация" Index="0"></Item><Item Name="Windows аутентификация" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_REMOTE_SERVER"><Map Name="RemoteServerID" Column="RemoteServerID"></Map><Map Name="Name" Column="Name"></Map><Map Name="ObjectUrl" Column="ObjectUrl"></Map><Map Name="AuthenticationType" Column="AuthenticationType"></Map><Map Name="ServerID" Column="ServerID"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='REMOTE_SERVER'
        GO
      