DROP SEQUENCE public.dfe_id_dfe_seq;

CREATE SEQUENCE public.dfe_id_dfe_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
ALTER TABLE public.dfe_id_dfe_seq
  OWNER TO postgres;

DROP TABLE public.dfe;

CREATE TABLE public.dfe
(
  id_dfe integer NOT NULL DEFAULT nextval('dfe_id_dfe_seq'::regclass),
  id_empresa integer NOT NULL,
  chave character varying(44) NOT NULL,
  nsu character varying(20),
  cnpj character varying(14),
  ie character varying(30),
  nome character varying(100),
  dataemissao date,
  dhrecebimento timestamp without time zone,
  valor numeric(15,3),
  dig character varying(40),
  nprot character varying(50),
  nseqevento integer,
  tipo_nf integer,
  situacao_nf integer,
  situacao_conf integer,
  situacao_xml integer,
  numero integer,
  serie integer,
  xml text,
  cod_compra integer,
  dhregevento timestamp without time zone,
  cstat integer,
  xmotivo character varying(60),
  nprotevento character varying(50),
  xmlevento text,
  tipo_evento character varying(20) NOT NULL,
  correcao character varying(255),
  CONSTRAINT pk_dfe PRIMARY KEY (id_dfe),
  CONSTRAINT fk_dfe_empresas FOREIGN KEY (id_empresa)
      REFERENCES public.empresas (emp_001) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE SET NULL
)