CREATE OR REPLACE FUNCTION ignore_accents(text)
RETURNS text AS
$BODY$
SELECT TRANSLATE($1,'áàãâäÁÀÃÂÄéèêëẽÉÈÊËẼíìîïĩÍÌÎÏĨóòõôöÓÒÕÔÖúùûüũÚÙÛÜŨñÑçÇÿýÝ', 'aaaaaAAAAAeeeeEEEEEEiiiiiIIIIIoooooOOOOOuuuuuUUUUUnNcCyyY')
$BODY$
LANGUAGE sql IMMUTABLE STRICT
COST 100;
ALTER FUNCTION ignore_accents(text)
OWNER TO postgres;
COMMENT ON FUNCTION ignore_accents(text) IS 'Ignore accents';

-- Hierachy change

ALTER TABLE fields
ADD COLUMN farm_id BIGINT;

ALTER TABLE fields
ADD CONSTRAINT fk_farm_id
FOREIGN KEY (farm_id) REFERENCES farms(id);

ALTER TABLE fields
ADD COLUMN soil_type_id BIGINT;

ALTER TABLE fields
ADD CONSTRAINT fk_soil_type_id
FOREIGN KEY (soil_type_id) REFERENCES soil_types(id);

alter table fields drop column crop_id;
alter table fields drop column culture_id;
alter table fields drop column planted_at;
alter table fields drop column cycle;

-- date utc with zone new field

alter table measurements add column dateutc_aux timestamp(0) without time zone;
update measurements set dateutc_aux = dateutc;
