Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
/*========tur===================================================*/
2
/* DBMS name:     PostgreSQL 8                                  */
3
/* Criado em:     03/07/2015                                        */
4
/* Autor: Bruno Lopes Peixoto                                       */
5
/*==============================================================*/
6
 
7
SET search_path = sc_sec;
8
 
9
CREATE SEQUENCE sq_categoria
10
INCREMENT 1
11
minvalue 1
12
maxvalue 99999999
13
START 1;
14
 
15
ALTER TABLE sq_categoria owner TO sc_sec;
16
 
17
/*==============================================================*/
18
/* Table: sec_categoria                                         */
19
/*==============================================================*/
20
CREATE TABLE sec_categoria (
21
   seq_categoria        INT8                 NOT NULL DEFAULT NEXTVAL('sc_sec.sq_categoria'::regclass),
22
   seq_categoria_pai    INT8                 NULL,
23
   dsc_categoria        VARCHAR(120)         NULL,
24
   tip_categoria        CHAR(1)              NULL
25
      CONSTRAINT ck_categoria_tipo CHECK (tip_categoria IS NULL OR (tip_categoria IN ('R','D'))),
26
   ind_ativo            BOOL                 NULL,
27
   CONSTRAINT pk_categoria PRIMARY KEY (seq_categoria)
28
);
29
 
30
comment ON COLUMN sec_categoria.tip_categoria IS
31
'Valores possíveis:
32
R - Receitas
33
D - Despesas';
34
 
35
-- set table ownership
36
ALTER TABLE sec_categoria owner TO sc_sec
37
;
38
/*==============================================================*/
39
/* Index: ix_categoria                                          */
40
/*==============================================================*/
41
CREATE UNIQUE INDEX ix_categoria ON sec_categoria (
42
seq_categoria
43
);
44
 
45
/*==============================================================*/
46
/* Index: ix_categoria_categoriapai                             */
47
/*==============================================================*/
48
CREATE  INDEX ix_categoria_categoriapai ON sec_categoria (
49
seq_categoria_pai
50
);
51
 
52
ALTER TABLE sec_categoria
53
   ADD CONSTRAINT fk_categoria_categoriapai FOREIGN KEY (seq_categoria_pai)
54
      REFERENCES sec_categoria (seq_categoria)
55
      ON DELETE RESTRICT ON UPDATE RESTRICT;
56
 
57
ALTER TABLE sec_conta_a_receber ADD COLUMN seq_categoria int8;
58
 
59
/*==============================================================*/
60
/* Index: ix_contaareceber_categoria                            */
61
/*==============================================================*/
62
CREATE  INDEX ix_contaareceber_categoria ON sec_conta_a_receber (
63
seq_categoria
64
);
65
 
66
ALTER TABLE sec_conta_a_receber
67
   ADD CONSTRAINT fk_contaareceber_categoria FOREIGN KEY (seq_categoria)
68
      REFERENCES sec_categoria (seq_categoria)
69
      ON DELETE RESTRICT ON UPDATE RESTRICT;
70
 
71
ALTER TABLE sec_conta_a_pagar ADD COLUMN seq_categoria int8;
72
 
73
/*==============================================================*/
74
/* Index: ix_contaapagar_categoria                              */
75
/*==============================================================*/
76
CREATE  INDEX ix_contaapagar_categoria ON sec_conta_a_pagar (
77
seq_categoria
78
);
79
 
80
ALTER TABLE sec_conta_a_pagar
81
   ADD CONSTRAINT fk_contaapagar_categoria FOREIGN KEY (seq_categoria)
82
      REFERENCES sec_categoria (seq_categoria)
83
      ON DELETE RESTRICT ON UPDATE RESTRICT;
84
 
85
SET search_path = public;