default
.pdf`surname` varchar(80) DEFAULT NULL,
`date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `users_type_id` bigint(20) NOT NULL,
`memo` varchar(250) DEFAULT NULL, PRIMARY KEY (`id`),
KEY `idx_users_type_id` (`users_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Дамп данных таблицы `users`
--
INSERT INTO `users` (`id`, `name`, `surname`, `date_creation`, `users_type_id`, `memo`)
VALUES
(1, 'alex', 'khrist', '2012-10-23 23:14:03', 1, NULL),
(2, 'ivan', 'kapitonov', '2012-10-23 23:14:05', 2, NULL),
(3, 'vadim', 'dragunov', '2012-10-23 23:22:37', 3, NULL),
(4, 'dima', 'zaslavskiy', '2012-11-09 23:33:37', 3, NULL);
--
--Триггеры `users`
DROP TRIGGER IF EXISTS `check_users_date_insert`; DELIMITER //
CREATE TRIGGER `check_users_date_insert` BEFORE INSERT ON `users` FOR EACH ROW begin
declare msg varchar(50);
--=======================================================
--Проверка вводимых данные на соответствие типам (домены)
--=======================================================
if length(new.name) > 80 then
set msg = concat('Error long Name, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.surname) > 80 then
set msg = concat('Error long surname, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.memo) > 250 then
set msg = concat('Error long Memo, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.users_type_id < 0 then
set msg = concat('Error user_type_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
21
end if;
end
//
DELIMITER ;
DROP TRIGGER IF EXISTS `check_users_date_update`;
DELIMITER //
CREATE TRIGGER `check_users_date_update` BEFORE UPDATE ON `users`
FOR EACH ROW begin
declare msg varchar(50);
--=======================================================
--Проверка вводимых данные на соответствие типам (домены)
--=======================================================
if length(new.name) > 80 then
set msg = concat('Error long Name, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.surname) > 80 then
set msg = concat('Error long surname, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.memo) > 250 then
set msg = concat('Error long Memo, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.users_type_id < 0 then
set msg = concat('Error user_type_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
end
//
DELIMITER ;
-- --------------------------------------------------------
--
-- Структура таблицы `users_type`
--
CREATE TABLE IF NOT EXISTS `users_type` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name_type` char(80) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_type` (`name_type`)
22
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Дамп данных таблицы `users_type`
--
INSERT INTO `users_type` (`id`, `name_type`) VALUES (1, 'admin'),
(2, 'redactor'), (3, 'user');
--
--Триггеры `users_type`
DROP TRIGGER IF EXISTS `check_user_type_date_insert`; DELIMITER //
CREATE TRIGGER `check_user_type_date_insert` BEFORE INSERT ON `users_type` FOR EACH ROW begin
declare msg varchar(50);
--=======================================================
--Проверка вводимых данные на соответствие типам (домены)
--=======================================================
if length(new.name_type) > 80 then
set msg = concat('Error long name_type, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
end
//
DELIMITER ;
-- --------------------------------------------------------
--
-- Структура таблицы `vertices`
--
CREATE TABLE IF NOT EXISTS `vertices` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `maps_id` bigint(20) unsigned NOT NULL,
`name` varchar(80) DEFAULT NULL,
`date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `user_id` bigint(20) DEFAULT NULL,
`axis_x` int(11) DEFAULT NULL, `axis_y` int(11) DEFAULT NULL, `memo` varchar(250) DEFAULT NULL, PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `user_id` (`user_id`),
KEY `maps_id` (`maps_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=63 ;
23
--
-- Дамп данных таблицы `vertices`
--
INSERT INTO `vertices` (`id`, `maps_id`, `name`, `date_creation`, `user_id`, `axis_x`, `axis_y`, `memo`) VALUES
(50, 1, '101', '2012-11-01 20:00:00', 1, NULL, NULL, NULL),
(51, 1, '102', '2012-11-01 20:01:00', 1, NULL, NULL, NULL),
(52, 1, '103', '2012-11-02 20:05:00', 3, NULL, NULL, NULL),
(53, 1, '104', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(54, 1, '105', '2012-11-02 21:06:00', 3, NULL, NULL, NULL),
(55, 1, '106', '2012-11-02 20:06:00', 3, NULL, NULL, NULL),
(56, 2, '201', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(57, 2, '202', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(58, 2, '203', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(59, 2, '204', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(60, 2, '205', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(61, 2, '206', '2012-11-05 20:17:06', 2, NULL, NULL, NULL),
(62, 2, '207', '2012-11-05 20:17:06', 2, NULL, NULL, NULL);
--
--Триггеры `vertices`
DROP TRIGGER IF EXISTS `check_vertices_date_insert`; DELIMITER //
CREATE TRIGGER `check_vertices_date_insert` BEFORE INSERT ON `vertices` FOR EACH ROW begin
declare msg varchar(50);
--=======================================================
--Проверка вводимых данные на соответствие типам (домены)
--=======================================================
if length(new.name) > 80 then
set msg = concat('Error long Name, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.memo) > 250 then
set msg = concat('Error long Memo, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.maps_id < 0 then
set msg = concat('Error maps_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.user_id < 0 then
24
set msg = concat('Error user_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.axis_x < 0 then
set msg = concat('Error axis_x, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.axis_y < 0 then
set msg = concat('Error axis_y, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
end
//
DELIMITER ;
DROP TRIGGER IF EXISTS `check_vertices_date_update`;
DELIMITER //
CREATE TRIGGER `check_vertices_date_update` BEFORE UPDATE ON `vertices` FOR EACH ROW begin
declare msg varchar(50);
--=======================================================
--Проверка вводимых данные на соответствие типам (домены)
--=======================================================
if length(new.name) > 80 then
set msg = concat('Error long Name, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if length(new.memo) > 250 then
set msg = concat('Error long Memo, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.maps_id < 0 then
set msg = concat('Error maps_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.user_id < 0 then
set msg = concat('Error user_id, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.axis_x < 0
25
then
set msg = concat('Error axis_x, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
if new.axis_y < 0 then
set msg = concat('Error axis_y, ID = ', cast(new.id as char)); signal sqlstate '45000' set message_text = msg;
end if;
end
//
DELIMITER ;
-- --------------------------------------------------------
--
--Дублирующая структура для представления `ver_on_maps`
CREATE TABLE IF NOT EXISTS `ver_on_maps` ( `maps_id` bigint(20) unsigned ,`maps_name` varchar(80)
,`vertices_id` bigint(20) unsigned ,`vertices_name` varchar(80) ,`axis_x` int(11)
,`axis_y` int(11) ,`maps_user` bigint(20) ,`vertices_user` bigint(20) ,`name_map` varchar(80) ,`name_ver` varchar(80)
);
----------------------------------------------------------
--
-- Структура для представления `edge_and_ver`
--
DROP TABLE IF EXISTS `edge_and_ver`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`edge_and_ver` AS select `e`.`id` AS `edge_id`,`e`.`name` AS `edge_name`,`e`.`length` AS `length`,`m`.`id` AS `id`,`m`.`name` AS `name_maps`,`u_m`.`name` AS `user_maps`,`m`.`user_id` AS
`maps_user_id`,`v1`.`id` |
|
AS |
`id_ver_1`,`v1`.`name` |
AS |
`name_ver_1`,`v2`.`id` |
AS |
|||||
`id_ver_2`,`v2`.`name` |
AS |
`name_ver_2` |
from |
((((`edge` |
`e` |
join |
`vertices` |
`v1` |
|||
on((`e`.`vertices_id_1` = |
`v1`.`id`))) |
join |
`vertices` |
|
`v2` |
on((`e`.`vertices_id_2` = |
|||||
`v2`.`id`))) join `maps` |
`m` |
on((`m`.`id` |
= `v1`.`maps_id`))) |
join |
`users` |
`u_m` |
on((`m`.`user_id` = `u_m`.`id`))) where (`e`.`edge_type` = 0);
-- --------------------------------------------------------
--
-- Структура для представления `edge_from_vert`
--
26
DROP TABLE IF EXISTS `edge_from_vert`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `edge_from_vert` AS select `v`.`id` AS `id_ver_1`,`v`.`name` AS `name_ver_1`,`e`.`id` AS `id_edge`,`e`.`name` AS `name_edge`,`e`.`length` AS `length`,`v2`.`id` AS `id_ver_2`,`v2`.`name` AS `name_ver_2` from ((`vertices` `v` join `edge` `e` on((`v`.`id` = `e`.`vertices_id_1`))) join `vertices` `v2` on((`e`.`vertices_id_2` = `v2`.`id`))) union select `v`.`id` AS `id`,`v`.`name` AS `name`,`e`.`id` AS `id`,`e`.`name` AS `name`,`e`.`length` AS `length`,`v2`.`id` AS `id_ver_2`,`v2`.`name` AS `name_ver_2` from ((`vertices` `v` join `edge` `e` on((`v`.`id` = `e`.`vertices_id_2`))) join `vertices` `v2` on((`e`.`vertices_id_1` = `v2`.`id`)));
-- --------------------------------------------------------
--
-- Структура для представления `edge_on_maps`
--
DROP TABLE IF EXISTS `edge_on_maps`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `edge_on_maps` AS select `e`.`id` AS `edge_id`,`e`.`name` AS `edge_name`,`e`.`length` AS `length`,`v1`.`maps_id` AS `maps_id`,`m`.`name` AS `name_maps`,`u_m`.`name` AS `user_maps`,`m`.`user_id` AS `maps_user_id`,`u_e`.`name` AS `user_edge`,`e`.`user_id` AS `edge_user_id` from ((((`edge` `e` join `vertices` `v1` on((`e`.`vertices_id_1` = `v1`.`id`))) join `maps` `m` on((`m`.`id` = `v1`.`maps_id`))) join `users` `u_m` on((`m`.`user_id` = `u_m`.`id`))) join `users` `u_e` on((`e`.`user_id` = `u_e`.`id`))) where (`e`.`edge_type` = 0);
-- --------------------------------------------------------
--
-- Структура для представления `ver_on_maps`
--
DROP TABLE IF EXISTS `ver_on_maps`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `ver_on_maps` AS select `m`.`id` AS `maps_id`,`m`.`name` AS `maps_name`,`v`.`id` AS `vertices_id`,`v`.`name` AS `vertices_name`,`v`.`axis_x` AS `axis_x`,`v`.`axis_y` AS `axis_y`,`m`.`user_id` AS `maps_user`,`v`.`user_id` AS `vertices_user`,`u`.`name` AS `name_map`,`u1`.`name` AS `name_ver` from (((`maps` `m` join `vertices` `v` on((`m`.`id` = `v`.`maps_id`))) join `users` `u` on((`m`.`user_id` = `u`.`id`))) join `users` `u1` on((`v`.`user_id` = `u1`.`id`)));
--
-- Ограничения внешнего ключа сохраненных таблиц
--
--
-- Ограничения внешнего ключа таблицы `edge`
--
ALTER TABLE `edge`
ADD CONSTRAINT `edge_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
ADD CONSTRAINT `edge_ibfk_2` FOREIGN KEY (`vertices_id_1`) REFERENCES `vertices` (`id`),
ADD CONSTRAINT `edge_ibfk_3` FOREIGN KEY (`vertices_id_2`) REFERENCES `vertices` (`id`);
--
-- Ограничения внешнего ключа таблицы `maps`
--
27
ALTER TABLE `maps`
ADD CONSTRAINT `maps_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
--
-- Ограничения внешнего ключа таблицы `users`
--
ALTER TABLE `users`
ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`users_type_id`) REFERENCES `users_type` (`id`);
--
-- Ограничения внешнего ключа таблицы `vertices`
--
ALTER TABLE `vertices`
ADD CONSTRAINT `vertices_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
ADD CONSTRAINT `vertices_ibfk_2` FOREIGN KEY (`maps_id`) REFERENCES `maps` (`id`);
/*!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 */;
grant select on Diagrams.* to user;
grant update (memo) on Diagrams.maps to user; grant update (memo) on Diagrams.users to user; grant update (memo) on Diagrams.edge to user; grant update (memo) on Diagrams.vertices to user;
grant select on Diagrams.* to redactor;
grant insert on Diagrams.vertices to redactor; grant insert on Diagrams.maps to redactor; grant insert on Diagrams.edge to redactor; grant delete on Diagrams.vertices to redactor; grant delete on Diagrams.maps to redactor; grant delete on Diagrams.edge to redactor; grant update on Diagrams.vertices to redactor; grant update on Diagrams.maps to redactor; grant update on Diagrams.edge to redactor;
28