Subversion Repositories Integrator Subversion

Rev

Blame | Last modification | View Log | Download | RSS feed

/*========tur===================================================*/
/* DBMS name:     PostgreSQL 8                                  */
/* Criado em:     03/07/2015                                        */
/* Autor: Bruno Lopes Peixoto                                       */
/*==============================================================*/

SET search_path = sc_sec;

CREATE SEQUENCE sq_categoria
INCREMENT 1
minvalue 1
maxvalue 99999999
START 1;

ALTER TABLE sq_categoria owner TO sc_sec;

/*==============================================================*/
/* Table: sec_categoria                                         */
/*==============================================================*/
CREATE TABLE sec_categoria (
   seq_categoria        INT8                 NOT NULL DEFAULT NEXTVAL('sc_sec.sq_categoria'::regclass),
   seq_categoria_pai    INT8                 NULL,
   dsc_categoria        VARCHAR(120)         NULL,
   tip_categoria        CHAR(1)              NULL
      CONSTRAINT ck_categoria_tipo CHECK (tip_categoria IS NULL OR (tip_categoria IN ('R','D'))),
   ind_ativo            BOOL                 NULL,
   CONSTRAINT pk_categoria PRIMARY KEY (seq_categoria)
);

comment ON COLUMN sec_categoria.tip_categoria IS
'Valores possíveis:
R - Receitas
D - Despesas'
;

-- set table ownership
ALTER TABLE sec_categoria owner TO sc_sec
;
/*==============================================================*/
/* Index: ix_categoria                                          */
/*==============================================================*/
CREATE UNIQUE INDEX ix_categoria ON sec_categoria (
seq_categoria
);

/*==============================================================*/
/* Index: ix_categoria_categoriapai                             */
/*==============================================================*/
CREATE  INDEX ix_categoria_categoriapai ON sec_categoria (
seq_categoria_pai
);

ALTER TABLE sec_categoria
   ADD CONSTRAINT fk_categoria_categoriapai FOREIGN KEY (seq_categoria_pai)
      REFERENCES sec_categoria (seq_categoria)
      ON DELETE RESTRICT ON UPDATE RESTRICT;

ALTER TABLE sec_conta_a_receber ADD COLUMN seq_categoria int8;

/*==============================================================*/
/* Index: ix_contaareceber_categoria                            */
/*==============================================================*/
CREATE  INDEX ix_contaareceber_categoria ON sec_conta_a_receber (
seq_categoria
);

ALTER TABLE sec_conta_a_receber
   ADD CONSTRAINT fk_contaareceber_categoria FOREIGN KEY (seq_categoria)
      REFERENCES sec_categoria (seq_categoria)
      ON DELETE RESTRICT ON UPDATE RESTRICT;
         
ALTER TABLE sec_conta_a_pagar ADD COLUMN seq_categoria int8;

/*==============================================================*/
/* Index: ix_contaapagar_categoria                              */
/*==============================================================*/
CREATE  INDEX ix_contaapagar_categoria ON sec_conta_a_pagar (
seq_categoria
);

ALTER TABLE sec_conta_a_pagar
   ADD CONSTRAINT fk_contaapagar_categoria FOREIGN KEY (seq_categoria)
      REFERENCES sec_categoria (seq_categoria)
      ON DELETE RESTRICT ON UPDATE RESTRICT;
         
SET search_path = public;