/*
 * V8_12_To_V8_3.java
 *
 * Created on December 19, 2007, 3:12 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package siprp.update.updates;

import com.evolute.utils.Singleton;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.Field;

/**
 *
 * @author fpalma
 */
public class V8_2_To_V8_3
		implements siprp.update.Update
{
	
	/**
	 * Creates a new instance of V8_2_To_V8_3
	 */
	public V8_2_To_V8_3()
	{
	}
	
	public String []listChanges()
	{
		return new String[]{ "Criar tabela para locais de an\u00e1lise" };
	}
	
	public double getStartVersion()
	{
		return 8.2;
	}
	
	public double getEndVersion()
	{
		return 8.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( 
				"CREATE TABLE trabalhadores_ecds_analise"
				+ "("
				+ "id serial, "
				+ "data date NOT NULL, "
				+ "prestador_id int4 NOT NULL, "
				+ "grupo_ecds_id int4 NOT NULL, "
				+ "CONSTRAINT trabalhadores_ecds_analise_pkey PRIMARY KEY (id), "
				+ "CONSTRAINT trabalhadores_ecds_analise_grupo_ecds_id_fkey FOREIGN KEY (grupo_ecds_id) "
				+ "	REFERENCES prt_grupos_protocolo (id) MATCH SIMPLE "
				+ "	ON UPDATE NO ACTION ON DELETE NO ACTION, "
				+ "CONSTRAINT trabalhadores_ecds_analise_prestador_id_fkey FOREIGN KEY (prestador_id) "
				+ "	REFERENCES prestadores (id) MATCH SIMPLE "
				+ " ON UPDATE NO ACTION ON DELETE NO ACTION "
				+ ") " 
				+ "WITHOUT OIDS; "
				+ "ALTER TABLE trabalhadores_ecds_analise OWNER TO postgres;" );
		executer.executeQuery( update );
	}
	
	public String toString()
	{
		return "v" + getStartVersion() + " para v" + getEndVersion();
	}
}
