-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.sql
226 lines (182 loc) · 5.65 KB
/
create.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
CREATE DATABASE IF NOT EXISTS `datawarehouse`;
USE `datawarehouse`;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `accounts`
--
CREATE TABLE `accounts` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`address` varchar(50) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`phone` varchar(50) DEFAULT NULL,
`city_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cities` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`country_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
CREATE TABLE `contacts` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`lastname` varchar(50) NOT NULL,
`position` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`address` varchar(50) DEFAULT NULL,
`interest` tinyint(4) DEFAULT NULL,
`city_id` int(11) DEFAULT NULL,
`account_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `contact_channels` (
`id` int(11) NOT NULL,
`contact_id` int(11) NOT NULL,
`type` enum('Phone','WhatsApp','Email','Facebook','Twitter','Instagram') NOT NULL,
`handle` varchar(50) DEFAULT '',
`preference` enum('No preference','Favourite','Do not disturb') NOT NULL DEFAULT 'No preference'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `countries` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`region_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
CREATE TABLE `regions` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`email` varchar(50) NOT NULL,
`profile` enum('admin','basic') NOT NULL DEFAULT 'basic',
`password` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indices de la tabla `accounts`
--
ALTER TABLE `accounts`
ADD PRIMARY KEY (`id`),
ADD KEY `FK__cities` (`city_id`);
--
-- Indices de la tabla `cities`
--
ALTER TABLE `cities`
ADD PRIMARY KEY (`id`) USING BTREE,
ADD KEY `FK_countries_regions` (`country_id`) USING BTREE;
--
-- Indices de la tabla `contacts`
--
ALTER TABLE `contacts`
ADD PRIMARY KEY (`id`),
ADD KEY `FK_contacts_cities` (`city_id`),
ADD KEY `FK_contacts_accounts` (`account_id`);
--
-- Indices de la tabla `contact_channels`
--
ALTER TABLE `contact_channels`
ADD PRIMARY KEY (`id`),
ADD KEY `FK__contacts` (`contact_id`);
--
-- Indices de la tabla `countries`
--
ALTER TABLE `countries`
ADD PRIMARY KEY (`id`) USING BTREE,
ADD KEY `FK_countries_regions` (`region_id`);
--
-- Indices de la tabla `regions`
--
ALTER TABLE `regions`
ADD PRIMARY KEY (`id`);
--
-- Indices de la tabla `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT de las tablas volcadas
--
--
-- AUTO_INCREMENT de la tabla `accounts`
--
ALTER TABLE `accounts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
--
-- AUTO_INCREMENT de la tabla `cities`
--
ALTER TABLE `cities`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT de la tabla `contacts`
--
ALTER TABLE `contacts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
--
-- AUTO_INCREMENT de la tabla `contact_channels`
--
ALTER TABLE `contact_channels`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;
--
-- AUTO_INCREMENT de la tabla `countries`
--
ALTER TABLE `countries`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT de la tabla `regions`
--
ALTER TABLE `regions`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT de la tabla `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- Restricciones para tablas volcadas
--
--
-- Filtros para la tabla `accounts`
--
ALTER TABLE `accounts`
ADD CONSTRAINT `FK__cities` FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`) ON DELETE SET NULL;
--
-- Filtros para la tabla `cities`
--
ALTER TABLE `cities`
ADD CONSTRAINT `FK_cities_countries` FOREIGN KEY (`country_id`) REFERENCES `countries` (`id`) ON DELETE CASCADE;
--
-- Filtros para la tabla `contacts`
--
ALTER TABLE `contacts`
ADD CONSTRAINT `FK_contacts_accounts` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE SET NULL,
ADD CONSTRAINT `FK_contacts_cities` FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`) ON DELETE SET NULL;
--
-- Filtros para la tabla `contact_channels`
--
ALTER TABLE `contact_channels`
ADD CONSTRAINT `FK__contacts` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE;
CREATE DATABASE IF NOT EXISTS `datawarehouse`;
USE `datawarehouse`;
--
-- Filtros para la tabla `countries`
--
ALTER TABLE `countries`
ADD CONSTRAINT `FK_countries_regions` FOREIGN KEY (`region_id`) REFERENCES `regions` (`id`) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
--
-- Volcado de datos para la tabla `users`
--
INSERT INTO `users` (`id`, `name`, `lastname`, `email`, `profile`, `password`) VALUES
(1, 'admin', 'admin', '[email protected]', 'admin', 'admin'),
(2, 'guest', 'guest', '[email protected]', 'basic', 'guest');