-- Adiciona novo tipo de camadas de linhas
insert into layer_types(id,name, uri, priority, name_en, name_es) values (16,'Camadas de linhas', 'line_layers', 2, 'Line layers', 'Capas de linea');

-- Cria tabela de camadas de linhas
CREATE TABLE IF NOT EXISTS public.line_layers
(
    id serial NOT NULL,
    crop_id integer NOT NULL,
    created_by integer NOT NULL,
    created_at timestamp(0) without time zone,
    updated_at timestamp(0) without time zone,
    field_id integer NOT NULL,
    coordinates text COLLATE pg_catalog."default" NOT NULL,
    line_geom geometry,
    machine_width double precision,
    edge_passes double precision,
    angle double precision,
    distance double precision,
    CONSTRAINT line_layers_pkey PRIMARY KEY (id),
    CONSTRAINT line_layers_created_by_fkey FOREIGN KEY (created_by)
        REFERENCES public.users (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT line_layers_crop_id_fkey FOREIGN KEY (crop_id)
        REFERENCES public.crops (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT line_layers_field_id_fkey FOREIGN KEY (field_id)
        REFERENCES public.fields (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);

ALTER TABLE IF EXISTS public.line_layers
    OWNER to postgres;