alter table users add column reset_password boolean not null default true;

-- Table: public.pest_disease_types

-- DROP TABLE IF EXISTS public.pest_disease_types;

CREATE TABLE IF NOT EXISTS public.pest_disease_types
(
    id bigserial,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    created_at timestamp(0) without time zone,
    updated_at timestamp(0) without time zone,
    CONSTRAINT pest_disease_types_pkey PRIMARY KEY (id)
);


-- Table: public.parameters

-- DROP TABLE IF EXISTS public.parameters;

CREATE TABLE IF NOT EXISTS public.parameters
(
    id bigserial,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    created_at timestamp(0) without time zone,
    updated_at timestamp(0) without time zone,
    CONSTRAINT parameters_pkey PRIMARY KEY (id)
);

-- Table: public.pest_diseases

-- DROP TABLE IF EXISTS public.pest_diseases;

CREATE TABLE IF NOT EXISTS public.pest_diseases
(
    id bigserial,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    type_id bigint NOT NULL,
    culture_id bigint NOT NULL,
    period smallint NOT NULL,
    script text COLLATE pg_catalog."default" NOT NULL,
    created_at timestamp(0) without time zone,
    updated_at timestamp(0) without time zone,
    CONSTRAINT pest_diseases_pkey PRIMARY KEY (id),
    CONSTRAINT pest_diseases_culture_id_foreign FOREIGN KEY (culture_id)
        REFERENCES public.cultures (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT pest_diseases_type_id_foreign FOREIGN KEY (type_id)
        REFERENCES public.pest_disease_types (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);


-- Table: public.pest_disease_parameter

-- DROP TABLE IF EXISTS public.pest_disease_parameter;

CREATE TABLE IF NOT EXISTS public.pest_disease_parameter
(
    id bigserial,
    parameter_id bigint NOT NULL,
    pest_disease_id bigint NOT NULL,
    greater_and_equal double precision NOT NULL,
    less_and_equal double precision NOT NULL,
    created_at timestamp(0) without time zone,
    updated_at timestamp(0) without time zone,
    CONSTRAINT pest_disease_parameter_pkey PRIMARY KEY (id),
    CONSTRAINT pest_disease_parameter_parameter_id_foreign FOREIGN KEY (parameter_id)
        REFERENCES public.parameters (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT pest_disease_parameter_pest_disease_id_foreign FOREIGN KEY (pest_disease_id)
        REFERENCES public.pest_diseases (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);

INSERT INTO parameters (name) 
VALUES 
    ('Temperatura'),
    ('Umidade'),
    ('Chuva');

INSERT INTO pest_disease_types (name) 
VALUES 
    ('Doença'),
    ('Praga');