
--Freemarker Template

--Nummernkreis wurde von 45xxx auf 48xxx geändert
create temp table tmp_delete_mask(maskeninfo_id integer);

insert into tmp_delete_mask(maskeninfo_id)
select tid from maskeninfo 
where (tid=45000 and name='Tabellenausgabe Studierende (amtlich und intern)')
or (tid=45040 and name='Spalten und Spaltenlayouts verwalten')
or (tid=45080 and name='Stellenbesetzung und Beschäftigung (Liste)');

delete from maskeninfo where tid in (select maskeninfo_id from tmp_delete_mask);
delete from  felderinfo where tid in (select felderinfo_id from masken_felder_bez where maskeninfo_id in (select maskeninfo_id from tmp_delete_mask));

delete from  sachgeb_maske_bez where maskeninfo_id in (select maskeninfo_id from tmp_delete_mask);
delete from  masken_felder_bez where maskeninfo_id in (select maskeninfo_id from tmp_delete_mask);
delete from maske_system_bez where maskeninfo_id in (select maskeninfo_id from tmp_delete_mask);
delete from themenbaum where maskeninfo_id in (select maskeninfo_id from tmp_delete_mask);
delete from macro_masken_bez where maskeninfo_id1 in (select maskeninfo_id from tmp_delete_mask);
delete from macro_masken_bez where maskeninfo_id2 in (select maskeninfo_id from tmp_delete_mask);
delete from macro_feld_wert where macro in (select maskeninfo_id from tmp_delete_mask);

drop table tmp_delete_mask;


<#if '${SQLdialect}'='Postgres' >

alter table rpta_resultset alter column fieldclause type text;
alter table rpta_resultset alter column joinclause type text;
alter table rpta_resultset alter column whereclause type text;
alter table rpta_column2layout ALTER COLUMN  is_visible SET DEFAULT 1;

</#if>

--update current sos module to most recent version:

update sx_fields set is_sum=0
where table_name in ('dim_studiengang','sos_stg_aggr','sos_k_stort','sos_k_stuart','sos_k_stutyp','sos_k_stufrm')
and name !='summe';


UPDATE sx_tables
   SET caption = 'Standorte'
WHERE name='sos_k_stort';
UPDATE sx_tables
   SET caption = 'Studienart'
WHERE name = 'sos_k_stuart';
UPDATE sx_tables
   SET caption = 'Studiumstyp'
WHERE name = 'sos_k_stutyp';
UPDATE sx_tables
   SET caption = 'Studienform'
WHERE name = 'sos_k_stufrm';



CREATE OR REPLACE VIEW sos_k_stutyp
(
  apnr,
  druck,
  astat
)
AS 
 SELECT cifx.apnr,
    cifx.druck,
    astat
   FROM cifx
  WHERE cifx.key = 40;

  select * into temp tmp_sos_k_stutyp_astat
  from sx_fields where table_name='sos_k_stutyp'
  and name='astat';
  
  INSERT INTO sx_fields
(
  table_name,
  name,
  caption,
  description,
  field_type,
  field_size,
  field_not_null,
  currentlyused,
  is_primarykey,
  foreignkey_tab,
  foreignkey_col,
  foreignkey_int,
  foreignkey_cap,
  foreignkey_cond,
  foreignkey_func,
  check_integrity,
  is_sum,
  foreignkey_uniquename
)
select 
  'sos_k_stutyp',
  'astat',
  'astat',
  '',
  'CHAR',
  '150',
  0,
  1,
  0,
  NULL,
  NULL,
  NULL,
  NULL,
  NULL,
  NULL,
  0,
  1,
  NULL
 from xdummy
 where 0=(select count(*) 
 from tmp_sos_k_stutyp_astat);
 
 drop table tmp_sos_k_stutyp_astat;
 
--Neue Spaltenbreite bei 0.3:
alter table rpta_column alter column col_function type TEXT;

