
DELETE FROM [VCLib].[T_JOB_STEP]
WHERE JobStepID = '7EC5243C-7F1A-4C6C-91E9-CB6016962560'
GO

DELETE FROM [VCLib].[T_JOB_SCHEDULE]
WHERE ScheduleID = '101EE8B7-B866-4B10-AE06-7D5871528661'
GO

DELETE FROM [VCLib].[T_SCHEDULER_OPERATION]
WHERE OperationID = 'F09071AD-A0BB-4C99-AEE7-8878B75D1A44'
GO

DELETE FROM [VCLib].[T_JOB]
WHERE JobID = '2A94DCF7-600D-435C-9284-63E822F03AA8'
GO

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

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

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

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

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

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

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

INSERT VCLib.T_JOB(JobID, Name, ConcurrentExecute)
SELECT 'f3f02176-eafc-4f87-98b4-33686b8d3f3b', N'Удаление IHE_CLINICALDOCUMENT_EVENT старше 30 дней через хэндлер', 0
GO

INSERT VCLib.T_JOB_STEP(JobStepID, Step, ContinueOnError, Job, [Operation])
SELECT 'dda5b219-01ab-4e5f-9c43-11af8020dc6e', 1, 0, 'f3f02176-eafc-4f87-98b4-33686b8d3f3b', 'f294395b-365e-4527-b67a-c8f6c0fe4e5f'
GO

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