VERS='6.03.001'

echo "Mise a jour de la base de donnees pour Version $VERS"

isql - - <<EOT

DATABASE gc;

UPDATE
  gc_parsys
SET
  version= '$VERS'
WHERE
  version<'$VERS';

UPDATE gc_parsys SET numcert="17/0097";

GRANT dba to "6.03";
GRANT dba to "6.03x";

drop table cr_signfac;
drop table cr_signlgf;
drop table cr_signgtt;
drop table cr_noaudit;
drop table cr_signaud;
drop table cr_dupfac;
drop table cr_signarch;
drop table cr_gtotaux;
drop table logaudit;

create table logaudit 
  (
    numdep smallint,
    nseek integer,
    gdh_d date,
    gdh_h integer,
    session integer,
    username char(10),
    func integer,
    op smallint,
    audlib char(80),
    compl char(80)
  );

create unique index ux_logaudit on logaudit (nseek);

create table cr_signfac 
  (
    nofac char(10),
    hashbase char(180),
    hash char(25),
    sign char(180),
    nofacprec char(10)
  );

create unique index ux_crsignfac01 on cr_signfac (nofac);
    
create table cr_signlgf 
  (
    nofac char(10),
    numlig smallint,
    hash char(25)
  );

create unique index ux_crsignlgf on cr_signlgf (nofac,numlig);

create table cr_signgtt 
  (
    id char(12),
    hashbase char(180),
    hash char(25),
    sign char(350),
    idprec char(12)
  );

create unique index ux_signgtt01 on cr_signgtt (id);
create table cr_noaudit 
  (
    ind smallint,
    numdep smallint,
    no integer
  );

create table cr_signaud 
  (
    numdep smallint,
    nofac char(10),
    hashbase char(180),
    hash char(25),
    sign char(180),
    nofacprec char(10)
  );

create unique index ux_crsignaud01 on cr_signaud (numdep,
    nofac);

create table cr_dupfac 
  (
    nofac char(10),
    dt date,
    hr integer,
    num smallint,
    username char(8),
    hashbase char(180),
    hash char(25),
    sign char(180),
    numprec smallint,
    nskprec integer,
    nseek serial not null 
  );

create unique index ux_dupfac on cr_dupfac (nofac,num);
create unique index ux_dupfac02 on cr_dupfac (nseek);

create table cr_signarch 
  (
    id char(20),
    dt date,
    numdep smallint,
    hashbase char(180),
    hash char(25),
    sign char(350),
    nskprec integer,
    nseek serial not null ,
    idprec char(20)
  );

create unique index ux_signarch01 on cr_signarch (nseek);
    
create unique index ux_signarch02 on cr_signarch (id);
create index ix_signarch03 on cr_signarch (numdep,dt desc,
    nseek desc);

create table cr_gtotaux 
  (
    id char(12),
    dt date,
    typ smallint,
    numdep smallint,
    gtmens float,
    gtperpet float,
    gtjour float,
    nseek serial not null,
    monttc1 float,
    monttc2 float,
    monttc3 float,
    monttc4 float,
    monttc5 float,
    monttc6 float,
    monttc7 float,
    monttc8 float,
    monttc9 float,
    txtva1 float,
    txtva2 float,
    txtva3 float,
    txtva4 float,
    txtva5 float,
    txtva6 float,
    txtva7 float,
    txtva8 float,
    txtva9 float,
    gtperpm float
  );

create unique index ux_gtotaux01 on cr_gtotaux (id);
create index ux_gtotaux02 on cr_gtotaux (numdep,dt desc,
    nseek desc);

CLOSE DATABASE;

EOT

chmod 666 $DBPATH/gc.dbs/*.idx
chmod 666 $DBPATH/gc.dbs/*.dat

rm -rf $DBPATH/archpdf
rm -rf $DBPATH/archivaud
rm -rf $DBPATH/archivefac

mkdir $DBPATH/archivefac
chmod 777 $DBPATH/archivefac

echo "Mise a jour terminee"
