DECLARE
  column_count NUMBER;
  index_count NUMBER;
BEGIN
  SELECT COUNT(*) INTO column_count
  FROM USER_TAB_COLUMNS
  WHERE TABLE_NAME = 'WORKFLOWPROCESSINSTANCE'
    AND COLUMN_NAME = 'CALENDARNAME';

  IF column_count = 0 THEN
    EXECUTE IMMEDIATE 'ALTER TABLE WORKFLOWPROCESSINSTANCE ADD (CALENDARNAME NVARCHAR2(1024))';
  END IF;

  SELECT COUNT(*) INTO index_count
  FROM USER_INDEXES
  WHERE INDEX_NAME = 'IDX_CALENDARNAME';

  IF index_count = 0 THEN
    EXECUTE IMMEDIATE 'CREATE INDEX IDX_CALENDARNAME ON WORKFLOWPROCESSINSTANCE (CALENDARNAME) LOGGING';
  END IF;
END;
