ALTER TABLE AKUZ.T_PHARMACY ADD "mail" varchar(200) NULL;

ALTER TABLE AKUZ.T_PHARMACY ADD "ehrrusbr9ap1s2qb" integer NULL;

ALTER TABLE AKUZ.T_PHARMACY ADD CONSTRAINT FK_T_EHR_RUS_BR9AP1S2QB_T_PHARMACY_EhrRusBr9ap1s2qb
FOREIGN KEY("ehrrusbr9ap1s2qb") REFERENCES EHR.T_EHR_RUS_BR9AP1S2QB (EhrRusID);

DO $$
declare
    _guid uuid := gen_random_uuid();
begin
    INSERT INTO vclib.t_object_modification_action (
        objectmodificationactionid,
        entities,
        position,
        type_,
        active,
        name,
        instruction,
        instructiontype
    )
    VALUES (
        _guid,
        (select entityid from vclib.t_entities where entname = 'PHARMACY' LIMIT 1),
        1,
        (select entityid from vclib.t_entities where entname = 'SINGLE_MODIFICATION_ACTION' LIMIT 1),
        false,
        'sp_RDS_Pharmacy',
        'sp_RDS_Pharmacy',
        0
    );

    INSERT INTO vclib.t_object_modification_action_param (
        objectmodificationactionparamid,
        objectmodificationaction,
        paramvalue,
        name
    )
    VALUES (
        gen_random_uuid(),
        _guid,
        '<lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepString name="ObjectProperties" /><lx:StepString name="IsNew" /></lx:Path>',
        '@IsNew'
    );

    INSERT INTO vclib.t_object_modification_action_param (
        objectmodificationactionparamid,
        objectmodificationaction,
        paramvalue,
        name
    )
    VALUES (
        gen_random_uuid(),
        _guid,
        '<lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepString name="Code" /></lx:Path>',
        '@ID'
    );
end $$;