-- replace demo data license with the standard license, so all existing standard data
-- will be replaced at the db import
update dt489 set DI041223='011' where DI041223 in ('100', '777');
update dt496 set DI041102='011' where DI041102 in ('100', '777');
update dt497 set DI041116='011' where DI041116 in ('100', '777');
update dt498 set DI041130='011' where DI041130 in ('100', '777');

-- Global settings: default process models
update DT333 set DI051828 = (case when DI051828 is null then null else '011' || lpad(DI051828, 6, '0') end)
where DI051831 in ('default_request_model',
                   'default_pm_model_idea',
                   'default_pm_model_intention',
                   'default_pm_model_project')
and DI051828 in (select DI041096 from DT496 where DI041102 in ('011', '100', '777'));

-- Global Variable 157: default process for mod 0099VH
update dt452 set DI003107 = (case when DI003107 is null then null else '011' || lpad(DI003107, 6, '0') end)
where DI003109 = 157
and DI003107 in (select DI041123 from DT498 where DI041130 in ('011', '100', '777'));

-- DT499 Objektprozess
alter table DT499 modify (DI041138 varchar2 (12 char));
alter table DT499 modify (DI057823 varchar2 (12 char));
alter table DT876 modify (DI057863 varchar2 (12 char));
alter table DT876 modify (DI057864 varchar2 (12 char));

update DT499 set DI057823 = (case when DI057823 is null then null else '011' || DI057823 end),
                 DI041145 = 'MIGRATION', DI041142=SYSTIMESTAMP
where DI061407 in (select DI041096 from DT496 where DI041102 in ('011', '100', '777'));

update DT876 set DI057863 = (case when DI057863 is null then null else '011' || DI057863 end),
                 DI057871 = 'MIGRATION', DI057868=SYSTIMESTAMP
where DI057863 in (select DI041138 from DT499 
                    where DI061407 in (select DI041096 from DT496 
                                       where DI041102 in ('011', '100', '777')));

update DT876 set DI057864 = (case when DI057864 is null then null else '011' || DI057864 end),
                 DI057871 = 'MIGRATION', DI057868=SYSTIMESTAMP
where DI057864 in (select DI041138 from DT499 
                    where DI061407 in (select DI041096 from DT496 
                                       where DI041102 in ('011', '100', '777')));

-- DT877 Objektprozess/Bericht
alter table DT877 modify (DI057896 varchar2 (12 char));
alter table DT877 modify (DI057897 varchar2 (12 char));

update DT877 set DI057896 = (case when DI057896 is null then null else '011' || DI057896 end),
                 DI057904='MIGRATION', DI057901=SYSTIMESTAMP
where DI057896 in (select DI041138 from DT499
                   where DI061407 in (select DI041096 from DT496 
                                      where DI041102 in ('011', '100', '777')));

update DT877 set DI057897 = (case when DI057897 is null then null else '011' || DI057897 end),
                 DI057904='MIGRATION', DI057901=SYSTIMESTAMP
where DI057897 in (select DI041138 from DT499
                   where DI061407 in (select DI041096 from DT496 
                                      where DI041102 in ('011', '100', '777')));

update DT499 set DI041138 = (case when DI041138 is null then null else '011' || DI041138 end),
                 DI041145 = 'MIGRATION', DI041142=SYSTIMESTAMP
where DI061407 in (select DI041096 from DT496 where DI041102 in ('011', '100', '777'));

-- DT489 Prozessregeln
alter table dt489 modify (DI041217 varchar2 (12 char));
alter table DT497 modify (DI059080 varchar2 (12 char));
alter table DT498 modify (DI041231 varchar2 (12 char));
alter table DT498 modify (DI059088 varchar2 (12 char));
alter table DT499 modify (DI057857 varchar2 (12 char));
alter table DT499 modify (DI059091 varchar2 (12 char));

update DT499 set DI057857 = (case when DI057857 is null then null else '011' || lpad(DI057857, 6, '0') end),
                 DI041145='MIGRATION', DI041142=SYSTIMESTAMP
where DI057857 in (select DI041217 from DT489 where DI041223 in ('011', '100', '777'));

update DT499 set DI059091 = (case when DI059091 is null then null else '011' || lpad(DI059091, 6, '0') end),
                 DI041145='MIGRATION', DI041142=SYSTIMESTAMP
where DI059091 in (select DI041217 from DT489 where DI041223 in ('011', '100', '777'));

-- DT496 Prozessmodell
alter table DT461 modify (DI041200 varchar2 (12 char));
alter table DT497 modify (DI041109 varchar2 (12 char));
alter table DT496 modify (DI041096 varchar2 (12 char));
alter table DT499 modify (DI061407 varchar2 (12 char));
alter table DT499 modify (DI057825 varchar2 (12 char));

update DT461 set DI041200 = (case when DI041200 is null then null else '011' || lpad(DI041200, 6, '0') end)
where DI041200 in (select DI041110 from DT497 
                   where DI041116 in ('011', '100', '777'));

update DT499 set DI061407 = (case when DI061407 is null then null else '011' || lpad(DI061407, 6, '0') end),
                 DI041145 = 'MIGRATION', DI041142=SYSTIMESTAMP
where DI061407 in (select DI041096 from DT496 where DI041102 in ('011', '100', '777'));

update dt499 set DI057825 = (case when DI057825 is null then null else '011' || lpad(DI057825, 6, '0') end),
                 DI041145 = 'MIGRATION', DI041142=SYSTIMESTAMP
where DI061407 in (select DI041096 from DT496 where DI041102 in ('011', '100', '777'));


-- DT497 Phase
alter table DT499 modify (DI041152 varchar2 (12 char));
alter table DT877 modify (DI059057 varchar2 (12 char));
alter table DT877 modify (DI059057 varchar2 (12 char));
alter table DT461 modify (DI059017 varchar2 (12 char));
alter table DT497 modify (DI041110 varchar2 (12 char));
alter table DT498 modify (DI041124 varchar2 (12 char));

update DT461 set DI059017 = (case when DI059017 is null then null else '011' || lpad(DI059017, 6, '0') end)
where DI059017 in (select DI041110 from DT497 
                   where DI041116 in ('011', '100', '777'));

update DT499 set DI041152 = (case when DI041152 is null then null else '011' || lpad(DI041152, 6, '0') end),
                             DI041145 = 'MIGRATION', DI041142=SYSTIMESTAMP
where DI041152 in (select DI041110 from DT497 where DI041116 in ('011', '100', '777'));

update DT877 set DI059057 = (case when DI059057 is null then null else '011' || DI059057 end),
                            DI057904='MIGRATION', DI057901=SYSTIMESTAMP
where DI059057 in (select DI041110 from DT497 where DI041116 in ('011', '100', '777'));


-- DT498 Prozess
alter table DT498 modify (DI041123 varchar2 (12 char));
alter table DT498 modify (DI057818 varchar2 (12 char));

-- DT876 Historie: Objektprozess
alter table DT876 modify (DI057880 varchar2 (21 char));


