CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
CREATE TABLE agendamentocoleta (
    id integer NOT NULL,
    usuario_id integer,
    endereco_id integer,
    empresa_coletora_id integer,
    situacao_agendamento_coleta integer,
    sequencial_rota integer,
    data_hora_agendamento timestamp without time zone NOT NULL,
    data_hora_registro timestamp without time zone,
    rota_id integer,
    usuario_notificado boolean DEFAULT false,
    avaliacao_id integer
);
ALTER TABLE public.agendamentocoleta OWNER TO postgres;
CREATE SEQUENCE agendamentocoleta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.agendamentocoleta_id_seq OWNER TO postgres;
ALTER SEQUENCE agendamentocoleta_id_seq OWNED BY agendamentocoleta.id;
CREATE TABLE avaliacao (
    id integer NOT NULL,
    agendamento_id integer,
    registro timestamp without time zone NOT NULL,
    comentarios text,
    pontual boolean,
    nota real,
    habilitado boolean
);
ALTER TABLE public.avaliacao OWNER TO postgres;
CREATE SEQUENCE avaliacao_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.avaliacao_id_seq OWNER TO postgres;
ALTER SEQUENCE avaliacao_id_seq OWNED BY avaliacao.id;
CREATE TABLE categoriaelixo (
    id integer NOT NULL,
    nome character varying(100),
    linha integer,
    ativo boolean DEFAULT true NOT NULL,
    classe character varying(2)
);
ALTER TABLE public.categoriaelixo OWNER TO postgres;
CREATE SEQUENCE categoriaelixo_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.categoriaelixo_id_seq OWNER TO postgres;
ALTER SEQUENCE categoriaelixo_id_seq OWNED BY categoriaelixo.id;
CREATE TABLE categoriaoperador (
    id integer NOT NULL,
    nome character varying(100),
    descricao character varying(100)
);
ALTER TABLE public.categoriaoperador OWNER TO postgres;
CREATE SEQUENCE categoriaoperador_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.categoriaoperador_id_seq OWNER TO postgres;
ALTER SEQUENCE categoriaoperador_id_seq OWNED BY categoriaoperador.id;
CREATE TABLE categorias_destinatarios (
    id integer NOT NULL,
    destinatario_id integer,
    categoria_id integer
);
ALTER TABLE public.categorias_destinatarios OWNER TO postgres;
CREATE SEQUENCE categorias_destinatarios_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.categorias_destinatarios_id_seq OWNER TO postgres;
ALTER SEQUENCE categorias_destinatarios_id_seq OWNED BY categorias_destinatarios.id;
CREATE TABLE categorias_empresas (
    empresacoletora_id integer,
    categoriaelixo_id integer,
    id integer NOT NULL
);
ALTER TABLE public.categorias_empresas OWNER TO postgres;
CREATE SEQUENCE categorias_empresas_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.categorias_empresas_id_seq OWNER TO postgres;
CREATE SEQUENCE categorias_empresas_id_seq1
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.categorias_empresas_id_seq1 OWNER TO postgres;
ALTER SEQUENCE categorias_empresas_id_seq1 OWNED BY categorias_empresas.id;
CREATE TABLE configuracao (
    id integer NOT NULL,
    fim_agendamento_manha_util time without time zone,
    inicio_agendamento_tarde_util time without time zone,
    fim_agendamento_tarde_util time without time zone,
    inicio_agendamento_manha_final_semana time without time zone,
    fim_agendamento_manha_final_semana time without time zone,
    inicio_agendamento_tarde_final_semana time without time zone,
    fim_agendamento_tarde_final_semana time without time zone,
    inicio_agendamento_manha_feriado time without time zone,
    fim_agendamento_manha_feriado time without time zone,
    inicio_agendamento_tarde_feriado time without time zone,
    fim_agendamento_tarde_feriado time without time zone,
    intervalo_agendamento_minutos_feriado integer,
    intervalo_agendamento_minutos_final_semana integer,
    intervalo_agendamento_minutos_util integer,
    inicio_agendamento_manha_util time without time zone
);
ALTER TABLE public.configuracao OWNER TO postgres;
CREATE SEQUENCE configuracao_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.configuracao_id_seq OWNER TO postgres;
ALTER SEQUENCE configuracao_id_seq OWNED BY configuracao.id;
CREATE TABLE destinatario (
    id integer NOT NULL,
    nome character varying,
    cpf character varying,
    cnpj character varying,
    endereco_id integer,
    data_criacao timestamp without time zone,
    ativo boolean,
    data_alteracao timestamp without time zone
);
ALTER TABLE public.destinatario OWNER TO postgres;
CREATE SEQUENCE destinatario_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.destinatario_id_seq OWNER TO postgres;
ALTER SEQUENCE destinatario_id_seq OWNED BY destinatario.id;
CREATE TABLE destinatarios_empresas (
    id integer NOT NULL,
    empresacoletora_id integer,
    destinatario_id integer
);
ALTER TABLE public.destinatarios_empresas OWNER TO postgres;
CREATE SEQUENCE destinatarios_empresas_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.destinatarios_empresas_id_seq OWNER TO postgres;
ALTER SEQUENCE destinatarios_empresas_id_seq OWNED BY destinatarios_empresas.id;
CREATE TABLE empresacoletora (
    id integer NOT NULL,
    nome_fantasia character varying(100),
    razao_social character varying(100),
    endereco_id integer,
    telefone_id integer,
    responsavel character varying(100),
    ativo boolean,
    cnpj character varying(100),
    rotas_diarias integer,
    raio_atuacao integer,
    email character varying(100),
    area character varying,
    logomarca character varying(200),
    assinatura character varying(200),
    credenciado boolean DEFAULT false NOT NULL,
    hash_grafico character varying
);
ALTER TABLE public.empresacoletora OWNER TO postgres;
CREATE SEQUENCE empresacoletora_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.empresacoletora_id_seq OWNER TO postgres;
ALTER SEQUENCE empresacoletora_id_seq OWNED BY empresacoletora.id;
CREATE TABLE endereco (
    id integer NOT NULL,
    tipo_endereco integer,
    tipo_logradouro character varying(100),
    logradouro character varying(100),
    numero character varying(100),
    complemento character varying(100),
    bairro character varying(100),
    cep character varying(100),
    referencia character varying(100),
    cidade character varying(100),
    usuario_id integer,
    lat real DEFAULT 0,
    lng real DEFAULT 0,
    estado integer,
    principal boolean DEFAULT false,
    habilitado boolean DEFAULT true
);
ALTER TABLE public.endereco OWNER TO postgres;
CREATE SEQUENCE endereco_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.endereco_id_seq OWNER TO postgres;
ALTER SEQUENCE endereco_id_seq OWNED BY endereco.id;
CREATE SEQUENCE estado_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.estado_id_seq OWNER TO postgres;
CREATE TABLE estoqueresiduo (
    id integer NOT NULL,
    empresa_id integer,
    categoria_id integer,
    tipo_id integer,
    total real
);
ALTER TABLE public.estoqueresiduo OWNER TO postgres;
CREATE SEQUENCE estoqueresiduo_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.estoqueresiduo_id_seq OWNER TO postgres;
ALTER SEQUENCE estoqueresiduo_id_seq OWNED BY estoqueresiduo.id;
CREATE TABLE grupoitemcoleta (
    id integer NOT NULL,
    agendamento_coleta_id integer,
    tipoelixo_id integer,
    quantidade_itens integer,
    peso_confirmado real,
    valor_confirmado real,
    embalagem boolean DEFAULT false,
    situacao integer,
    categoriaelixo_id integer,
    imagens text,
    destino character varying
);
ALTER TABLE public.grupoitemcoleta OWNER TO postgres;
CREATE SEQUENCE grupoitemcoleta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.grupoitemcoleta_id_seq OWNER TO postgres;
ALTER SEQUENCE grupoitemcoleta_id_seq OWNED BY grupoitemcoleta.id;
CREATE TABLE historico (
    id integer NOT NULL,
    agendamento_id integer,
    empresa_id integer,
    rota_id integer,
    inicio_coleta time without time zone,
    fim_coleta time without time zone,
    rota_gerada text
);
ALTER TABLE public.historico OWNER TO postgres;
CREATE SEQUENCE historico_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.historico_id_seq OWNER TO postgres;
ALTER SEQUENCE historico_id_seq OWNED BY historico.id;
CREATE TABLE historicoestoqueresiduo (
    id integer NOT NULL,
    data timestamp without time zone,
    estoque_residuo_id integer,
    operacao integer,
    quantidade_operacao integer,
    quantidade_anterior integer,
    quantidade_atual integer,
    destinatario_id integer
);
ALTER TABLE public.historicoestoqueresiduo OWNER TO postgres;
CREATE SEQUENCE historicoestoqueresiduo_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.historicoestoqueresiduo_id_seq OWNER TO postgres;
ALTER SEQUENCE historicoestoqueresiduo_id_seq OWNED BY historicoestoqueresiduo.id;
CREATE TABLE mtr (
    id integer NOT NULL,
    agendamento_id integer,
    codigo character varying(20),
    validado boolean DEFAULT true,
    dataregistro timestamp without time zone,
    nome_donatario character varying,
    razao_donatario character varying,
    cnpj_donatario character varying,
    endereco_donatario character varying,
    cidade_donatario character varying,
    estado_donatario character varying,
    versao integer,
    nome_gerador character varying,
    cpf_gerador character varying,
    cnpj_gerador character varying,
    rg_gerador character varying,
    endereco_gerador character varying,
    cidade_gerador character varying,
    estado_gerador character varying,
    cep_donatario character varying,
    numero_donatario character varying,
    bairro_donatario character varying,
    razao_gerador character varying,
    numero integer,
    tipo_veiculo character varying,
    forma_acondicionamento character varying,
    nome_veiculo character varying,
    motorista character varying
);
ALTER TABLE public.mtr OWNER TO postgres;
CREATE SEQUENCE mtr_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.mtr_id_seq OWNER TO postgres;
ALTER SEQUENCE mtr_id_seq OWNED BY mtr.id;
CREATE TABLE ocorrencia (
    id integer NOT NULL,
    tipoocorrencia_id integer,
    denunciante_id integer,
    denunciado_id integer,
    dataocorrencia date,
    descricao character varying,
    agendamento_id integer,
    situacao integer,
    data_hora_registro timestamp without time zone NOT NULL,
    empresa_id integer
);
ALTER TABLE public.ocorrencia OWNER TO postgres;
CREATE SEQUENCE ocorrencia_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.ocorrencia_id_seq OWNER TO postgres;
ALTER SEQUENCE ocorrencia_id_seq OWNED BY ocorrencia.id;
CREATE TABLE operador (
    id integer NOT NULL,
    nome_completo character varying(100) NOT NULL,
    nome_usuario character varying(100),
    ativo boolean,
    hash_senha character varying,
    categoria_id integer,
    email character varying(100),
    cpf character varying(100),
    rg character varying(100),
    empresa_id integer,
    data_hora_cadastro timestamp without time zone,
    ultima_alteracao_senha timestamp without time zone,
    ultima_autenticacao timestamp without time zone
);
ALTER TABLE public.operador OWNER TO postgres;
CREATE SEQUENCE operador_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.operador_id_seq OWNER TO postgres;
ALTER SEQUENCE operador_id_seq OWNED BY operador.id;
CREATE TABLE rede_social (
    id integer NOT NULL,
    id_usuario integer,
    rede_social character varying(100)
);
ALTER TABLE public.rede_social OWNER TO postgres;
CREATE SEQUENCE rede_social_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.rede_social_id_seq OWNER TO postgres;
ALTER SEQUENCE rede_social_id_seq OWNED BY rede_social.id;
CREATE TABLE rota (
    id integer NOT NULL,
    data timestamp without time zone NOT NULL,
    situacao integer DEFAULT 1,
    data_criacao timestamp without time zone,
    nome character(100),
    saida_coletora time without time zone,
    chegada_coletora time without time zone,
    empresa_id integer
);
ALTER TABLE public.rota OWNER TO postgres;
CREATE SEQUENCE rota_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.rota_id_seq OWNER TO postgres;
ALTER SEQUENCE rota_id_seq OWNED BY rota.id;
CREATE TABLE sugestao (
    id integer NOT NULL,
    usuario_id integer NOT NULL,
    responsavel_adm_id integer,
    texto text,
    respondida_adm boolean DEFAULT false NOT NULL,
    comentarios_adm text,
    data_hora_recebimento timestamp without time zone NOT NULL,
    data_hora_resposta_adm timestamp without time zone,
    responsavel_emp_id integer,
    respondida_emp boolean,
    comentarios_emp text,
    data_hora_resposta_emp timestamp without time zone,
    habilitar_comentarios_emp boolean,
    empresa_id integer
);
ALTER TABLE public.sugestao OWNER TO postgres;
CREATE SEQUENCE sugestao_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.sugestao_id_seq OWNER TO postgres;
ALTER SEQUENCE sugestao_id_seq OWNED BY sugestao.id;
CREATE TABLE telefone (
    id integer NOT NULL,
    tipo_telefone integer DEFAULT 1,
    ddi integer,
    ddd integer,
    recado character varying(100),
    usuario_id integer,
    numero character varying(100),
    sms boolean DEFAULT false
);
ALTER TABLE public.telefone OWNER TO postgres;
CREATE SEQUENCE telefone_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.telefone_id_seq OWNER TO postgres;
ALTER SEQUENCE telefone_id_seq OWNED BY telefone.id;
CREATE TABLE termodedescarte (
    id integer NOT NULL,
    agendamento_id integer,
    codigo character varying(20),
    validado boolean DEFAULT true,
    dataregistro timestamp without time zone,
    nome_donatario character varying,
    cnpj_donatario character varying,
    endereco_donatario character varying,
    cidade_donatario character varying,
    estado_donatario character varying,
    versao integer,
    nome_doador character varying,
    cpf_doador character varying,
    rg_doador character varying,
    endereco_doador character varying,
    cidade_doador character varying,
    estado_doador character varying
);
ALTER TABLE public.termodedescarte OWNER TO postgres;
CREATE SEQUENCE termodedescarte_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.termodedescarte_id_seq OWNER TO postgres;
ALTER SEQUENCE termodedescarte_id_seq OWNED BY termodedescarte.id;
CREATE TABLE termodedoacao (
    id integer NOT NULL,
    agendamento_id integer,
    codigo character varying,
    testemunha1 character varying,
    testemunha2 character varying,
    validado boolean DEFAULT true,
    dataregistro timestamp without time zone,
    nome_doador character varying,
    cpf_doador character varying,
    rg_doador character varying,
    endereco_doador character varying,
    cidade_doador character varying,
    estado_doador character varying,
    nome_donatario character varying,
    cnpj_donatario character varying,
    endereco_donatario character varying,
    cidade_donatario character varying,
    estado_donatario character varying
);
ALTER TABLE public.termodedoacao OWNER TO postgres;
CREATE SEQUENCE termodedoacao_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.termodedoacao_id_seq OWNER TO postgres;
ALTER SEQUENCE termodedoacao_id_seq OWNED BY termodedoacao.id;
CREATE TABLE tipoelixo (
    id integer NOT NULL,
    nome character varying(100),
    categoria_id integer,
    peso_estimado real,
    altura real,
    largura real,
    profundidade real,
    ativo boolean DEFAULT true NOT NULL,
    termo_doacao boolean DEFAULT false
);
ALTER TABLE public.tipoelixo OWNER TO postgres;
CREATE SEQUENCE tipoelixo_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.tipoelixo_id_seq OWNER TO postgres;
ALTER SEQUENCE tipoelixo_id_seq OWNED BY tipoelixo.id;
CREATE TABLE tipoocorrencia (
    id integer NOT NULL,
    nome character varying
);
ALTER TABLE public.tipoocorrencia OWNER TO postgres;
CREATE SEQUENCE tipoocorrencia_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.tipoocorrencia_id_seq OWNER TO postgres;
ALTER SEQUENCE tipoocorrencia_id_seq OWNED BY tipoocorrencia.id;
CREATE TABLE usuario (
    id integer NOT NULL,
    nome_completo character varying(100) NOT NULL,
    rg character varying(100),
    cpf character varying(100) NOT NULL,
    mae character varying(100),
    pai character varying(100),
    data_nascimento character varying(100),
    emissor_rg character varying(100),
    uf_emissor_rg character varying(100),
    ativo boolean,
    hash_senha character varying,
    email character varying(100),
    data_hora_cadastro timestamp without time zone,
    ultima_alteracao_senha timestamp without time zone,
    ultima_autenticacao timestamp without time zone,
    cod_verificador character varying,
    tipo_usuario integer DEFAULT 1,
    cnpj character varying(100),
    razao_social character varying(100),
    nome_fantasia character varying(100),
    id_facebook character varying(255),
    termo_descarte boolean DEFAULT false NOT NULL,
    empresa_id integer
);
ALTER TABLE public.usuario OWNER TO postgres;
CREATE SEQUENCE usuario_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER TABLE public.usuario_id_seq OWNER TO postgres;
ALTER SEQUENCE usuario_id_seq OWNED BY usuario.id;
ALTER TABLE ONLY agendamentocoleta ALTER COLUMN id SET DEFAULT nextval('agendamentocoleta_id_seq'::regclass);
ALTER TABLE ONLY avaliacao ALTER COLUMN id SET DEFAULT nextval('avaliacao_id_seq'::regclass);
ALTER TABLE ONLY categoriaelixo ALTER COLUMN id SET DEFAULT nextval('categoriaelixo_id_seq'::regclass);
ALTER TABLE ONLY categorias_destinatarios ALTER COLUMN id SET DEFAULT nextval('categorias_destinatarios_id_seq'::regclass);
ALTER TABLE ONLY categorias_empresas ALTER COLUMN id SET DEFAULT nextval('categorias_empresas_id_seq1'::regclass);
ALTER TABLE ONLY configuracao ALTER COLUMN id SET DEFAULT nextval('configuracao_id_seq'::regclass);
ALTER TABLE ONLY destinatario ALTER COLUMN id SET DEFAULT nextval('destinatario_id_seq'::regclass);
ALTER TABLE ONLY destinatarios_empresas ALTER COLUMN id SET DEFAULT nextval('destinatarios_empresas_id_seq'::regclass);
ALTER TABLE ONLY empresacoletora ALTER COLUMN id SET DEFAULT nextval('empresacoletora_id_seq'::regclass);
ALTER TABLE ONLY endereco ALTER COLUMN id SET DEFAULT nextval('endereco_id_seq'::regclass);
ALTER TABLE ONLY estoqueresiduo ALTER COLUMN id SET DEFAULT nextval('estoqueresiduo_id_seq'::regclass);
ALTER TABLE ONLY grupoitemcoleta ALTER COLUMN id SET DEFAULT nextval('grupoitemcoleta_id_seq'::regclass);
ALTER TABLE ONLY historico ALTER COLUMN id SET DEFAULT nextval('historico_id_seq'::regclass);
ALTER TABLE ONLY historicoestoqueresiduo ALTER COLUMN id SET DEFAULT nextval('historicoestoqueresiduo_id_seq'::regclass);
ALTER TABLE ONLY mtr ALTER COLUMN id SET DEFAULT nextval('mtr_id_seq'::regclass);
ALTER TABLE ONLY ocorrencia ALTER COLUMN id SET DEFAULT nextval('ocorrencia_id_seq'::regclass);
ALTER TABLE ONLY operador ALTER COLUMN id SET DEFAULT nextval('operador_id_seq'::regclass);
ALTER TABLE ONLY rede_social ALTER COLUMN id SET DEFAULT nextval('rede_social_id_seq'::regclass);
ALTER TABLE ONLY rota ALTER COLUMN id SET DEFAULT nextval('rota_id_seq'::regclass);
ALTER TABLE ONLY sugestao ALTER COLUMN id SET DEFAULT nextval('sugestao_id_seq'::regclass);
ALTER TABLE ONLY telefone ALTER COLUMN id SET DEFAULT nextval('telefone_id_seq'::regclass);
ALTER TABLE ONLY termodedescarte ALTER COLUMN id SET DEFAULT nextval('termodedescarte_id_seq'::regclass);
ALTER TABLE ONLY termodedoacao ALTER COLUMN id SET DEFAULT nextval('termodedoacao_id_seq'::regclass);
ALTER TABLE ONLY tipoelixo ALTER COLUMN id SET DEFAULT nextval('tipoelixo_id_seq'::regclass);
ALTER TABLE ONLY tipoocorrencia ALTER COLUMN id SET DEFAULT nextval('tipoocorrencia_id_seq'::regclass);
ALTER TABLE ONLY usuario ALTER COLUMN id SET DEFAULT nextval('usuario_id_seq'::regclass);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT agendamentocoleta_pkey PRIMARY KEY (id);
ALTER TABLE ONLY avaliacao
    ADD CONSTRAINT avaliacao_pkey PRIMARY KEY (id);
ALTER TABLE ONLY categoriaelixo
    ADD CONSTRAINT categoriaelixo_pkey PRIMARY KEY (id);
ALTER TABLE ONLY categoriaoperador
    ADD CONSTRAINT categoriaoperador_pkey PRIMARY KEY (id);
ALTER TABLE ONLY categorias_destinatarios
    ADD CONSTRAINT categorias_destinatarios_pkey PRIMARY KEY (id);
ALTER TABLE ONLY categorias_empresas
    ADD CONSTRAINT categorias_empresas_pkey PRIMARY KEY (id);
ALTER TABLE ONLY termodedescarte
    ADD CONSTRAINT codigo_unique UNIQUE (codigo, versao);
ALTER TABLE ONLY configuracao
    ADD CONSTRAINT configuracao_pkey PRIMARY KEY (id);
ALTER TABLE ONLY destinatario
    ADD CONSTRAINT destinatario_pkey PRIMARY KEY (id);
ALTER TABLE ONLY destinatarios_empresas
    ADD CONSTRAINT destinatariosempresas_pkey PRIMARY KEY (id);
ALTER TABLE ONLY empresacoletora
    ADD CONSTRAINT empresacoletora_pkey PRIMARY KEY (id);
ALTER TABLE ONLY endereco
    ADD CONSTRAINT endereco_pkey PRIMARY KEY (id);
ALTER TABLE ONLY estoqueresiduo
    ADD CONSTRAINT estoqueresiduo_pkey PRIMARY KEY (id);
ALTER TABLE ONLY grupoitemcoleta
    ADD CONSTRAINT grupoitemcoleta_pkey PRIMARY KEY (id);
ALTER TABLE ONLY historico
    ADD CONSTRAINT historico_coleta_pkey PRIMARY KEY (id);
ALTER TABLE ONLY historicoestoqueresiduo
    ADD CONSTRAINT historicoestoqueresiduo_pkey PRIMARY KEY (id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT id PRIMARY KEY (id);
ALTER TABLE ONLY rede_social
    ADD CONSTRAINT id_pkey PRIMARY KEY (id);
ALTER TABLE ONLY mtr
    ADD CONSTRAINT mtr_pkey PRIMARY KEY (id);
ALTER TABLE ONLY operador
    ADD CONSTRAINT operador_pkey PRIMARY KEY (id);
ALTER TABLE ONLY rota
    ADD CONSTRAINT rota_pkey PRIMARY KEY (id);
ALTER TABLE ONLY sugestao
    ADD CONSTRAINT sugestao_pkey PRIMARY KEY (id);
ALTER TABLE ONLY telefone
    ADD CONSTRAINT telefone_pkey PRIMARY KEY (id);
ALTER TABLE ONLY termodedescarte
    ADD CONSTRAINT termodedescarte_pkey PRIMARY KEY (id);
ALTER TABLE ONLY termodedoacao
    ADD CONSTRAINT termodedoacao_pkey PRIMARY KEY (id);
ALTER TABLE ONLY tipoelixo
    ADD CONSTRAINT tipoelixo_pkey PRIMARY KEY (id);
ALTER TABLE ONLY tipoocorrencia
    ADD CONSTRAINT tipoocorrencia_pkey PRIMARY KEY (id);
ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_pkey PRIMARY KEY (id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT agendamento FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY grupoitemcoleta
    ADD CONSTRAINT agendamento_coleta_fkey FOREIGN KEY (agendamento_coleta_id) REFERENCES agendamentocoleta(id) ON DELETE CASCADE;
ALTER TABLE ONLY avaliacao
    ADD CONSTRAINT agendamento_fkey FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY historico
    ADD CONSTRAINT agendamento_fkey FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY termodedoacao
    ADD CONSTRAINT agendamento_fkey FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY termodedescarte
    ADD CONSTRAINT agendamento_fkey FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY mtr
    ADD CONSTRAINT agendamento_fkey FOREIGN KEY (agendamento_id) REFERENCES agendamentocoleta(id);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT avaliacao_fkey FOREIGN KEY (avaliacao_id) REFERENCES avaliacao(id) ON DELETE CASCADE;
ALTER TABLE ONLY estoqueresiduo
    ADD CONSTRAINT categoria_fkey FOREIGN KEY (categoria_id) REFERENCES categoriaelixo(id);
ALTER TABLE ONLY categorias_destinatarios
    ADD CONSTRAINT categoria_fkey FOREIGN KEY (categoria_id) REFERENCES categoriaelixo(id);
ALTER TABLE ONLY categorias_empresas
    ADD CONSTRAINT categoria_pkey FOREIGN KEY (categoriaelixo_id) REFERENCES categoriaelixo(id);
ALTER TABLE ONLY grupoitemcoleta
    ADD CONSTRAINT categoriaelixo_fkey FOREIGN KEY (categoriaelixo_id) REFERENCES categoriaelixo(id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT denunciado FOREIGN KEY (denunciado_id) REFERENCES usuario(id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT denunciante FOREIGN KEY (denunciante_id) REFERENCES operador(id);
ALTER TABLE ONLY historicoestoqueresiduo
    ADD CONSTRAINT destinatario_fkey FOREIGN KEY (destinatario_id) REFERENCES destinatario(id);
ALTER TABLE ONLY categorias_destinatarios
    ADD CONSTRAINT destinatario_fkey FOREIGN KEY (destinatario_id) REFERENCES destinatario(id);
ALTER TABLE ONLY destinatarios_empresas
    ADD CONSTRAINT destinatario_fkey FOREIGN KEY (destinatario_id) REFERENCES destinatario(id);
ALTER TABLE ONLY sugestao
    ADD CONSTRAINT empresa_fk1 FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT empresa_fkey FOREIGN KEY (empresa_coletora_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY historico
    ADD CONSTRAINT empresa_fkey FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY rota
    ADD CONSTRAINT empresa_fkey FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY estoqueresiduo
    ADD CONSTRAINT empresa_fkey FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY destinatarios_empresas
    ADD CONSTRAINT empresa_fkey FOREIGN KEY (empresacoletora_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT empresa_id FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY categorias_empresas
    ADD CONSTRAINT empresa_pkey FOREIGN KEY (empresacoletora_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY operador
    ADD CONSTRAINT empresacoletora_fk FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id) ON UPDATE SET NULL ON DELETE SET NULL;
ALTER TABLE ONLY usuario
    ADD CONSTRAINT empresacoletora_fk FOREIGN KEY (empresa_id) REFERENCES empresacoletora(id);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT endereco_fkey FOREIGN KEY (endereco_id) REFERENCES endereco(id);
ALTER TABLE ONLY destinatario
    ADD CONSTRAINT endereco_fkey FOREIGN KEY (endereco_id) REFERENCES endereco(id);
ALTER TABLE ONLY historicoestoqueresiduo
    ADD CONSTRAINT estoqueresiduo_fkey FOREIGN KEY (estoque_residuo_id) REFERENCES estoqueresiduo(id);
ALTER TABLE ONLY sugestao
    ADD CONSTRAINT fk3789a809ee03355 FOREIGN KEY (usuario_id) REFERENCES usuario(id);
ALTER TABLE ONLY empresacoletora
    ADD CONSTRAINT fk3789a809ee32125 FOREIGN KEY (telefone_id) REFERENCES telefone(id);
ALTER TABLE ONLY empresacoletora
    ADD CONSTRAINT fk3789a809ee34325 FOREIGN KEY (endereco_id) REFERENCES endereco(id);
ALTER TABLE ONLY tipoelixo
    ADD CONSTRAINT fk3789a809ee46348 FOREIGN KEY (categoria_id) REFERENCES categoriaelixo(id);
ALTER TABLE ONLY sugestao
    ADD CONSTRAINT responsavel_adm_id FOREIGN KEY (responsavel_adm_id) REFERENCES operador(id);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT rota_fk FOREIGN KEY (rota_id) REFERENCES rota(id);
ALTER TABLE ONLY historico
    ADD CONSTRAINT rota_fkey FOREIGN KEY (rota_id) REFERENCES rota(id);
ALTER TABLE ONLY estoqueresiduo
    ADD CONSTRAINT tipo_fkey FOREIGN KEY (tipo_id) REFERENCES tipoelixo(id);
ALTER TABLE ONLY grupoitemcoleta
    ADD CONSTRAINT tipoelixo_id FOREIGN KEY (tipoelixo_id) REFERENCES tipoelixo(id);
ALTER TABLE ONLY ocorrencia
    ADD CONSTRAINT tipoocorrencia_id FOREIGN KEY (tipoocorrencia_id) REFERENCES tipoocorrencia(id) ON DELETE CASCADE;
ALTER TABLE ONLY endereco
    ADD CONSTRAINT usuario_fkey FOREIGN KEY (usuario_id) REFERENCES usuario(id);
ALTER TABLE ONLY agendamentocoleta
    ADD CONSTRAINT usuario_fkey FOREIGN KEY (usuario_id) REFERENCES usuario(id);
ALTER TABLE ONLY telefone
    ADD CONSTRAINT usuario_fkey FOREIGN KEY (usuario_id) REFERENCES usuario(id);
REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;
