
DELETE FROM VCLib.T_JOB_STEP
WHERE JobStepID = '7ec5243c-7f1a-4c6c-91e9-cb6016962560'::uuid;

DELETE FROM VCLib.T_JOB_SCHEDULE
WHERE ScheduleID = '101ee8b7-b866-4b10-ae06-7d5871528661'::uuid;

DELETE FROM VCLib.T_SCHEDULER_OPERATION
WHERE OperationID = 'f09071ad-a0bb-4c99-aee7-8878b75d1a44'::uuid;

DELETE FROM VCLib.T_JOB
WHERE JobID = '2a94dcf7-600d-435c-9284-63e822f03aa8'::uuid;

DELETE FROM VCLib.T_JOB_STEP
WHERE JobStepID = 'dda5b219-01ab-4e5f-9c43-11af8020dc6e'::uuid;

DELETE FROM VCLib.T_JOB_SCHEDULE
WHERE ScheduleID = '421e9037-93a0-4955-8b1f-cdb957e29783'::uuid;

DELETE FROM VCLib.T_RUN_LEXEM_OPERATION
WHERE OperationID = 'f294395b-365e-4527-b67a-c8f6c0fe4e5f'::uuid;

DELETE FROM VCLib.T_SCHEDULER_OPERATION
WHERE OperationID = 'f294395b-365e-4527-b67a-c8f6c0fe4e5f'::uuid;

DELETE FROM VCLib.T_JOB
WHERE JobID = 'f3f02176-eafc-4f87-98b4-33686b8d3f3b'::uuid;

INSERT INTO VCLib.T_SCHEDULER_OPERATION (OperationID, type_, Name)
VALUES ('f294395b-365e-4527-b67a-c8f6c0fe4e5f'::uuid, (select EntityID from vclib.t_entities where EntName = 'RUN_LEXEM_OPERATION' limit 1), 'Удаление IHE_CLINICALDOCUMENT_EVENT старше 30 дней через хэндлер');

INSERT INTO VCLib.T_RUN_LEXEM_OPERATION (OperationID, Lexem)
VALUES ('f294395b-365e-4527-b67a-c8f6c0fe4e5f'::uuid,
'begin(p, params)
         @p := new Process("DropExpiredIheClinicalDocumentEventProcess");
         @p -> {Parameters}["DeleteBatchSize"] := 5000;
         @p -> Run()[@p];
      end');

INSERT INTO VCLib.T_JOB (JobID, Name, ConcurrentExecute)
VALUES ('f3f02176-eafc-4f87-98b4-33686b8d3f3b'::uuid, 'Удаление IHE_CLINICALDOCUMENT_EVENT старше 30 дней через хэндлер', false);

INSERT INTO VCLib.T_JOB_STEP (JobStepID, Step, ContinueOnError, Job, Operation)
VALUES ('dda5b219-01ab-4e5f-9c43-11af8020dc6e'::uuid, 1, false,
        'f3f02176-eafc-4f87-98b4-33686b8d3f3b'::uuid,
        'f294395b-365e-4527-b67a-c8f6c0fe4e5f'::uuid);

INSERT INTO VCLib.T_JOB_SCHEDULE (ScheduleID, Job, Type, Mask, StartDate, EndDate, Occurs, Recurs, StartTime, Enabled)
VALUES ('421e9037-93a0-4955-8b1f-cdb957e29783'::uuid,
        'f3f02176-eafc-4f87-98b4-33686b8d3f3b'::uuid,
        2,
        NULL,
        '2008-01-01 00:00:00'::timestamp,
        NULL,
        0,
        1,
        '2007-05-17 01:00:00'::timestamp,
        true);