forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1059 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
0b03933a8b
commit
5a1628caeb
@ -0,0 +1,78 @@
|
|||||||
|
package siprp.update.updates;
|
||||||
|
|
||||||
|
import siprp.higiene.gestao.importacao.Importador;
|
||||||
|
|
||||||
|
import com.evolute.utils.Singleton;
|
||||||
|
import com.evolute.utils.db.DBManager;
|
||||||
|
import com.evolute.utils.db.Executer;
|
||||||
|
|
||||||
|
public class V11_2_To_V11_3 implements siprp.update.Update
|
||||||
|
{
|
||||||
|
|
||||||
|
public V11_2_To_V11_3()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public String []listChanges()
|
||||||
|
{
|
||||||
|
return new String[]{
|
||||||
|
"Higiene e seguranca: a repor datas de submissao dos relatorios"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getStartVersion()
|
||||||
|
{
|
||||||
|
return 11.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getEndVersion()
|
||||||
|
{
|
||||||
|
return 11.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doUpdate() throws Exception
|
||||||
|
{
|
||||||
|
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||||
|
Executer executer = dbm.getSharedExecuter();
|
||||||
|
com.evolute.utils.sql.Update update =
|
||||||
|
new com.evolute.utils.sql.Update(
|
||||||
|
"alter table hs_relatorio_posto_risco add column id serial; " +
|
||||||
|
"create table hs_relatorio_posto_risco_temp( " +
|
||||||
|
"id serial, " +
|
||||||
|
" posto_id integer NOT NULL, " +
|
||||||
|
" risco_id integer NOT NULL, " +
|
||||||
|
" probabilidade integer, " +
|
||||||
|
" severidade integer, " +
|
||||||
|
" valor_qualitativo_id integer, " +
|
||||||
|
"CONSTRAINT hs_relatorio_posto_risco_temp_pkey PRIMARY KEY (posto_id, risco_id), " +
|
||||||
|
"CONSTRAINT hs_relatorio_posto_risco_posto_id_fkey FOREIGN KEY (posto_id) " +
|
||||||
|
"REFERENCES hs_relatorio_posto (id) MATCH SIMPLE " +
|
||||||
|
"ON UPDATE NO ACTION ON DELETE NO ACTION, " +
|
||||||
|
"CONSTRAINT hs_relatorio_posto_risco_risco_id_fkey FOREIGN KEY (risco_id) " +
|
||||||
|
"REFERENCES hs_relatorio_risco (id) MATCH SIMPLE " +
|
||||||
|
"ON UPDATE NO ACTION ON DELETE NO ACTION, " +
|
||||||
|
"CONSTRAINT hs_relatorio_posto_risco_valor_qualitativo_id_fkey FOREIGN KEY (valor_qualitativo_id) " +
|
||||||
|
"REFERENCES hs_relatorio_risco_valor_qualitativo (id) MATCH SIMPLE " +
|
||||||
|
"ON UPDATE NO ACTION ON DELETE NO ACTION " +
|
||||||
|
"); " +
|
||||||
|
"ALTER TABLE hs_relatorio_posto_risco OWNER TO postgres; " +
|
||||||
|
"insert into hs_relatorio_posto_risco_temp (posto_id,risco_id,probabilidade,severidade,valor_qualitativo_id) " +
|
||||||
|
" (select posto_id,risco_id,probabilidade,severidade,valor_qualitativo_id from hs_relatorio_posto_risco); " +
|
||||||
|
"update hs_relatorio_posto_risco set id = (select hs_relatorio_posto_risco_temp.id from hs_relatorio_posto_risco_temp " +
|
||||||
|
"where hs_relatorio_posto_risco_temp.posto_id = hs_relatorio_posto_risco.posto_id " +
|
||||||
|
"and hs_relatorio_posto_risco_temp.risco_id = hs_relatorio_posto_risco.risco_id); " +
|
||||||
|
"alter table hs_relatorio_posto_risco add constraint hs_relatorio_posto_risco_unique UNIQUE(posto_id,risco_id); " +
|
||||||
|
"alter table hs_relatorio_posto_risco drop constraint hs_relatorio_posto_risco_pkey; " +
|
||||||
|
"alter table hs_relatorio_posto_risco add constraint hs_relatorio_posto_risco_pkey PRIMARY KEY(id); " +
|
||||||
|
"drop table hs_relatorio_posto_risco_temp; "
|
||||||
|
);
|
||||||
|
executer.executeQuery( update );
|
||||||
|
new Importador( executer ).importar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "v" + getStartVersion() + " para v" + getEndVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue