-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql-add-carteiras.sql
170 lines (152 loc) · 5.49 KB
/
sql-add-carteiras.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
159
160
161
162
163
164
165
166
167
168
169
170
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema neogelk
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema neogelk
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `neogelk` DEFAULT CHARACTER SET utf8mb4 ;
USE `neogelk` ;
-- -----------------------------------------------------
-- Table `neogelk`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`users` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`email` VARCHAR(100) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`permissao` INT NOT NULL DEFAULT 1 COMMENT '1 = usuario default, 100 = admin.',
PRIMARY KEY (`id`));
-- -----------------------------------------------------
-- Table `neogelk`.`tipo_titulos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`tipo_titulos` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`descricao` VARCHAR(100) NOT NULL,
`user_id` CHAR(36) NULL,
PRIMARY KEY (`id`),
INDEX `fk_tipo_titulos_users1_idx` (`user_id` ASC),
CONSTRAINT `fk_tipo_titulos_users1`
FOREIGN KEY (`user_id`)
REFERENCES `neogelk`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- -----------------------------------------------------
-- Table `neogelk`.`titulos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`titulos` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`nome` VARCHAR(100) NOT NULL,
`ticker` VARCHAR(15) NULL,
`tipo_titulo_id` CHAR(36) NOT NULL,
`moeda` VARCHAR(45) NOT NULL DEFAULT 'real',
`user_id` CHAR(36) NULL,
PRIMARY KEY (`id`),
INDEX `fk_ativos_tipo_ativos_idx` (`tipo_titulo_id` ASC),
INDEX `fk_titulos_users1_idx` (`user_id` ASC),
CONSTRAINT `fk_ativos_tipo_ativos`
FOREIGN KEY (`tipo_titulo_id`)
REFERENCES `neogelk`.`tipo_titulos` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_titulos_users1`
FOREIGN KEY (`user_id`)
REFERENCES `neogelk`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- -----------------------------------------------------
-- Table `neogelk`.`carteiras`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`carteiras` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`nome` VARCHAR(100) NOT NULL,
`observacao` TEXT NULL,
PRIMARY KEY (`id`));
-- -----------------------------------------------------
-- Table `neogelk`.`ativos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`ativos` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`dt_compra` DATETIME NOT NULL,
`dt_venda` DATETIME NULL,
`quantidade` DECIMAL(15,4) NOT NULL DEFAULT 0,
`titulo_id` CHAR(36) NOT NULL,
`user_id` CHAR(36) NOT NULL,
`carteiras_id` CHAR(36) NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_ativos_titulos1_idx` (`titulo_id` ASC),
INDEX `fk_ativos_users1_idx` (`user_id` ASC),
INDEX `fk_ativos_carteiras1_idx` (`carteiras_id` ASC),
CONSTRAINT `fk_ativos_titulos1`
FOREIGN KEY (`titulo_id`)
REFERENCES `neogelk`.`titulos` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_ativos_users1`
FOREIGN KEY (`user_id`)
REFERENCES `neogelk`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_ativos_carteiras1`
FOREIGN KEY (`carteiras_id`)
REFERENCES `neogelk`.`carteiras` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- -----------------------------------------------------
-- Table `neogelk`.`cotacaos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`cotacaos` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`data` DATETIME NOT NULL,
`valor` DECIMAL(15,2) NOT NULL,
`ativo_id` CHAR(36) NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_cotacaos_ativos1_idx` (`ativo_id` ASC),
CONSTRAINT `fk_cotacaos_ativos1`
FOREIGN KEY (`ativo_id`)
REFERENCES `neogelk`.`ativos` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `neogelk`.`proventos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `neogelk`.`proventos` (
`id` CHAR(36) NOT NULL,
`created` DATETIME NOT NULL,
`modified` DATETIME NULL,
`deleted` DATETIME NULL,
`ativo_id` CHAR(36) NOT NULL,
`valor_total` DECIMAL(15,4) NOT NULL DEFAULT 0,
`descricao` VARCHAR(45) NULL,
`valor_individual` DECIMAL(15,4) NULL,
PRIMARY KEY (`id`),
INDEX `fk_proventos_ativos1_idx` (`ativo_id` ASC),
CONSTRAINT `fk_proventos_ativos1`
FOREIGN KEY (`ativo_id`)
REFERENCES `neogelk`.`ativos` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;