-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redline.sql
159 lines (142 loc) · 5.96 KB
/
redline.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
--
-- initial database schema for reference. for updated schema see the knex
-- migrations in service-node-koa/app/config/db/migrations
--
create table modelocategoria
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
cor varchar(255) default '#f00' not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null
);
create unique index modelocategoria_descricao_unique
on modelocategoria (descricao);
create table tipo_conta
(
id integer not null
primary key,
descricao varchar(255) not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null
);
create unique index tipo_conta_descricao_unique
on tipo_conta (descricao);
create table tipo_movimentacao
(
id integer not null
primary key,
descricao varchar(255) not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null
);
create unique index tipo_movimentacao_descricao_unique
on tipo_movimentacao (descricao);
create table tipo_recorrencia
(
id integer not null
primary key,
descricao varchar(255) not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null
);
create unique index tipo_recorrencia_descricao_unique
on tipo_recorrencia (descricao);
create table usuario
(
id integer not null
primary key autoincrement,
nome varchar(255) not null,
email varchar(255) not null,
senha varchar(255) not null,
admin boolean default '0' not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null
);
create table categoria
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
cor varchar(255) default '#f00' not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null,
usuario_id integer not null
references usuario
on delete cascade
);
create unique index categoria_descricao_usuario_id_unique
on categoria (descricao, usuario_id);
create table conta
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
ativa boolean default '1' not null,
cor varchar(255) default '#f00' not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null,
usuario_id integer not null
references usuario
on delete cascade,
tipo_conta_id integer not null
references tipo_conta,
dia_fechamento integer,
dia_vencimento integer,
limite float
);
create table planejamento
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null,
inicial datetime default CURRENT_TIMESTAMP not null,
final datetime default CURRENT_TIMESTAMP not null,
categoria_id integer not null
references categoria
on delete cascade,
limite float not null
);
create table recorrencia
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
valor float not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null,
inicial datetime default CURRENT_TIMESTAMP not null,
final datetime default CURRENT_TIMESTAMP not null,
tipo_recorrencia_id integer not null
references tipo_recorrencia,
usuario_id integer not null
references usuario
on delete cascade
);
create table movimentacao
(
id integer not null
primary key autoincrement,
descricao varchar(255) not null,
valor float not null,
criacao datetime default CURRENT_TIMESTAMP not null,
alteracao datetime default CURRENT_TIMESTAMP not null,
vencimento datetime default CURRENT_TIMESTAMP not null,
efetivada datetime,
tipo_movimentacao_id integer not null
references tipo_movimentacao,
conta_id integer not null
references conta
on delete cascade,
categoria_id integer
references categoria
on delete set null,
recorrencia_id integer
references recorrencia
on delete cascade
);
create unique index usuario_email_unique
on usuario (email);