declare
    WORKING_SET_ID constant   numeric := 2450;
    oldest_branch_created_at timestamp;
begin
    -- get oldest branch creation date
    select min(br.created_at)
    into oldest_branch_created_at
    from object_reference ref
             join object br on br.id = ref.to_id
    where ref.from_id = WORKING_SET_ID
      and br.type_id = 36;

    -- update working set creation time to oldest branch creation date
    UPDATE object
    SET created_at = oldest_branch_created_at
    WHERE object.id = WORKING_SET_ID;

    UPDATE object_revision
    SET created_at = oldest_branch_created_at
    WHERE object_id = WORKING_SET_ID;

    -- update associations (ws - tracker/branch/baseline) created time to oldest brnahc creation date
    UPDATE object
    SET created_at = oldest_branch_created_at
    WHERE object.id in (
        select ref.assoc_id
        from object_reference ref
                 join object o on o.id = ref.to_id and o.type_id in (36, 12)
        where ref.from_id = WORKING_SET_ID);

    UPDATE object_revision
    SET created_at = oldest_branch_created_at
    WHERE object_revision.object_id in (
        select ref.assoc_id
        from object_reference ref
                 join object o on o.id = ref.to_id and o.type_id in (36, 12)
        where ref.from_id = WORKING_SET_ID);
end;
/

