-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc-manager.sql
131 lines (108 loc) · 5.36 KB
/
doc-manager.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
DROP DATABASE IF exists `docmanager`;
CREATE DATABASE `docmanager`;
DROP TABLE IF EXISTS `docmanager`.`roles`;
CREATE TABLE `docmanager`.`roles` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(32) NOT NULL,
PRIMARY KEY(`id`))
ENGINE = InnoDB;
DROP TABLE IF EXISTS `docmanager`.`companies`;
CREATE TABLE `docmanager`.`companies` (
`id` INT NOT NULL AUTO_INCREMENT,
`short_name` VARCHAR(32) NOT NULL,
`full_name` VARCHAR(128) NOT NULL,
PRIMARY KEY(`id`))
ENGINE = InnoDB;
DROP TABLE IF EXISTS `docmanager`.`users`;
CREATE TABLE `docmanager`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(32) NOT NULL,
`password`VARCHAR(128) NOT NULL,
`salt` VARCHAR(64) NOT NULL,
`name` VARCHAR(128) NOT NULL,
`email` VARCHAR(128) NOT NULL,
`registration_date` DATETIME NOT NULL,
`enabled` BIT NOT NULL,
`role_id` INT NOT NULL,
PRIMARY KEY(`id`),
INDEX `fk_user1` (`role_id` ASC),
CONSTRAINT `fk_user1`
FOREIGN KEY (`role_id`)
REFERENCES `docmanager`.`roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE=InnoDB;
DROP TABLE IF EXISTS `docmanager`.`document_types`;
CREATE TABLE `docmanager`.`document_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `doc_type_fk1_idx` (`parent_id`),
CONSTRAINT `doc_type_fk1` FOREIGN KEY (`parent_id`) REFERENCES `docmanager`.`document_types` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `docmanager`.`document_status`;
CREATE TABLE `docmanager`.`document_status` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`document_type_id` int(11) NOT NULL,
`value` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
KEY `doc_type_fk_idx` (`document_type_id`),
CONSTRAINT `doc_type_fk` FOREIGN KEY (`document_type_id`) REFERENCES `docmanager`.`document_types` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `docmanager`.`document_fields`;
CREATE TABLE `docmanager`.`document_fields` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`document_type_id` INT NOT NULL,
`field_type` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
INDEX `document_type_fk1_idx` (`document_type_id` ASC),
CONSTRAINT `document_type_fk1`
FOREIGN KEY (`document_type_id`)
REFERENCES `docmanager`.`document_types` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `docmanager`.`documents`;
CREATE TABLE `docmanager`.`documents` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`file_name` varchar(256) NOT NULL,
`document_type_id` int(11) NOT NULL,
`content` mediumblob NOT NULL,
`content_type` varchar(32) NOT NULL,
`creation_date` datetime NOT NULL,
`company_id` int(11) NOT NULL,
`document_status_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_document1` (`document_type_id`),
KEY `fk_document2` (`company_id`),
KEY `doc_status_fk1_idx` (`document_status_id`),
CONSTRAINT `doc_status_fk1` FOREIGN KEY (`document_status_id`) REFERENCES `docmanager`.`document_status` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_document1` FOREIGN KEY (`document_type_id`) REFERENCES `docmanager`.`document_types` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT `fk_document2` FOREIGN KEY (`company_id`) REFERENCES `docmanager`.`companies` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `docmanager`.`field_values`;
CREATE TABLE `docmanager`.`field_values` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`value` varchar(45) NOT NULL,
`document_id` int(11) NOT NULL,
`document_field_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `doc_fk1_idx` (`document_id`),
KEY `doc_field_fk1_idx` (`document_field_id`),
CONSTRAINT `doc_fk1` FOREIGN KEY (`document_id`) REFERENCES `docmanager`.`documents` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `doc_field_fk1` FOREIGN KEY (`document_field_id`) REFERENCES `docmanager`.`document_fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
INSERT INTO `docmanager`.`roles` (`name`) VALUES ('ADMIN');
INSERT INTO `docmanager`.`roles` (`name`) VALUES ('USER');
INSERT INTO `docmanager`.`document_types` (`name`) VALUES ('document_type_1');
INSERT INTO `docmanager`.`document_types` (`name`) VALUES ('document_type_2');
INSERT INTO `docmanager`.`document_types` (`name`, `parent_id`) VALUES ('document_type_3', 1);
INSERT INTO `docmanager`.`companies` (`short_name`, `full_name`) VALUES ('comp_1', 'Company 1 GmbH');
INSERT INTO `docmanager`.`companies` (`short_name`, `full_name`) VALUES ('comp_2', 'Company 2 GmbH');
INSERT INTO `docmanager`.`companies` (`short_name`, `full_name`) VALUES ('comp_3', 'Company 3 GmbH');
INSERT INTO `docmanager`.`users` (`username`, `password`, `salt`, `name`, `email`, `registration_date`, `enabled`, `role_id`) VALUES ('jmachado', 'password', 'salt', 'João Machado', '[email protected]', '2013-11-12', 1, '1');
INSERT INTO `docmanager`.`users` (`username`, `password`, `salt`, `name`, `email`, `registration_date`, `enabled`, `role_id`) VALUES ('pserra', 'password', 'salt', 'João Machado', '[email protected]', '2013-11-12', 1, '1');
INSERT INTO `docmanager`.`users` (`username`, `password`, `salt`, `name`, `email`, `registration_date`, `enabled`, `role_id`) VALUES ('ptorra', 'password', 'salt', 'João Machado', '[email protected]', '2013-11-12', 1, '1');