-- Версия сервера: 10.1.21-MariaDB
-- Версия PHP: 7.1.2-2+deb.sury.org~xenial+1

--
-- База данных: `lib`
--

--
-- Структура таблицы `library_reader`
--

CREATE TABLE `library_reader` (
  `id` int(11) NOT NULL,
  `library_id` int(11) NOT NULL,
  `user` bigint(20) NOT NULL DEFAULT '0',
  `name` varchar(64) NOT NULL,
  `email` varchar(64) NOT NULL,
  `ticket` varchar(32) NOT NULL,
  `birth` date NOT NULL DEFAULT '1970-01-01',
  `cell` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active_at` timestamp NOT NULL DEFAULT '1970-01-01 09:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Дамп данных таблицы `library_reader`
--

INSERT INTO `library_reader` VALUES(1, 1, 1, 'Иван Иванович', 'user@user.name', '2134', '1950-12-16', 5, '2016-12-09 08:29:44', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1);
INSERT INTO `library_reader` VALUES(2, 1, 0, 'Иван Сергеевич', 'user@user.name', '435', '2000-12-16', 5, '2016-12-06 11:14:17', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0);
INSERT INTO `library_reader` VALUES(3, 1, 0, 'Антон Егорьевич', 'user@user.name', '3511', '1990-12-16', 5, '2016-12-07 08:22:27', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1);
INSERT INTO `library_reader` VALUES(4, 1, 0, 'Олег Антонович', 'user@user.name', '3423', '1875-12-16', 5, '2016-12-07 08:22:35', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0);
INSERT INTO `library_reader` VALUES(5, 1, 0, 'Елизавета Максимовна', 'user@user.name', '49723', '2005-12-16', 5, '2016-12-07 08:22:49', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0);
INSERT INTO `library_reader` VALUES(12, 1, 0, 'Юрий Иванович Оганесян', 'oganes@mail.ua', '123456', '1967-12-07', 5, '2016-12-28 10:36:12', '2016-12-28 10:36:12', '1970-01-01 09:00:00', 0);
INSERT INTO `library_reader` VALUES(17, 1, 0, 'Иван Сергеевич Рухля', 'ruhlya@oganes.ah', '1235937537733', '1980-11-03', 5, '2016-12-28 13:55:20', '2016-12-28 13:55:20', '1970-01-01 09:00:00', 1);
INSERT INTO `library_reader` VALUES(18, 1, 0, 'Тесак Ньютон', 'mail@mail.net', '777', '2000-10-10', 5, '2016-12-28 16:15:10', '2016-12-28 16:15:10', '1970-01-01 09:00:00', 1);

-- --------------------------------------------------------

--
-- Структура таблицы `library_reader_resource`
--

CREATE TABLE `library_reader_resource` (
  `id` int(11) NOT NULL,
  `library_id` int(11) NOT NULL,
  `library_reader_id` int(11) DEFAULT NULL,
  `resource_id` int(11) NOT NULL,
  `status` enum('queue','appove','reject','return','wait','take') NOT NULL,
  `comment` varchar(255) DEFAULT '',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `until` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Дамп данных таблицы `library_reader_resource`
--

INSERT INTO `library_reader_resource` VALUES(1, 1, 4, 21421, 'queue', '', '2017-01-11 13:52:07', '0000-00-00 00:00:00', '2016-12-09 21:00:00');
INSERT INTO `library_reader_resource` VALUES(2, 1, 1, 10021, 'take', '', '2016-12-02 13:52:07', '0000-00-00 00:00:00', '2016-12-09 21:00:00');
INSERT INTO `library_reader_resource` VALUES(3, 1, 3, 10042, 'return', '', '2016-12-02 13:52:13', '2016-12-05 15:00:00', '0000-00-00 00:00:00');
INSERT INTO `library_reader_resource` VALUES(4, 1, 3, 45640, 'return', '', '2016-12-02 13:52:07', '0000-00-00 00:00:00', '2016-12-09 21:00:00');
INSERT INTO `library_reader_resource` VALUES(5, 1, 1, 51783, 'return', '', '2016-12-08 15:17:36', '0000-00-00 00:00:00', '0000-00-00 00:00:00');
INSERT INTO `library_reader_resource` VALUES(14, 1, 18, 11646, 'queue', '', '2017-01-17 09:45:50', '2017-01-16 09:45:50', '2017-01-25 05:15:50');
INSERT INTO `library_reader_resource` VALUES(15, 1, 5, 11646, 'queue', '', '2017-01-16 09:50:00', '2017-01-16 09:50:00', '2017-01-25 05:20:00');
INSERT INTO `library_reader_resource` VALUES(16, 1, 1, 11646, 'take', '', '2017-01-16 09:53:11', '2017-01-16 09:53:11', '2017-01-25 05:23:11');
INSERT INTO `library_reader_resource` VALUES(17, 1, 17, 11646, 'queue', '', '2017-01-25 13:00:30', '2017-01-16 09:54:03', '2017-01-25 05:24:03');
INSERT INTO `library_reader_resource` VALUES(18, 1, 1, 11646, 'take', '', '2017-01-16 09:54:33', '2017-01-16 09:54:33', '2017-01-25 05:24:33');
INSERT INTO `library_reader_resource` VALUES(19, 1, 1, 11646, 'take', '', '2017-01-16 09:54:55', '2017-01-16 09:54:55', '2017-01-25 05:24:55');
INSERT INTO `library_reader_resource` VALUES(20, 1, 12, 11646, 'take', '', '2017-01-16 09:55:34', '2017-01-16 09:55:34', '2017-01-25 05:25:34');
INSERT INTO `library_reader_resource` VALUES(21, 1, 1, 11646, 'take', '', '2017-01-20 07:44:00', '2017-01-16 09:55:47', '2017-01-25 05:25:47');
INSERT INTO `library_reader_resource` VALUES(22, 1, 1, 11646, 'queue', '', '2017-01-16 09:56:11', '2017-01-16 09:56:11', '2017-01-25 05:26:11');
INSERT INTO `library_reader_resource` VALUES(23, 1, 1, 11646, 'take', '', '2017-01-16 09:56:19', '2017-01-16 09:56:19', '2017-01-25 05:26:19');
INSERT INTO `library_reader_resource` VALUES(24, 1, 1, 11646, 'take', '', '2017-01-16 10:00:25', '2017-01-16 10:00:25', '2017-01-25 05:30:25');
INSERT INTO `library_reader_resource` VALUES(25, 1, 1, 11646, 'take', '', '2017-01-16 10:00:34', '2017-01-16 10:00:34', '2017-01-25 05:30:34');
INSERT INTO `library_reader_resource` VALUES(26, 1, 2, 11646, 'queue', '', '2017-01-16 10:01:13', '2017-01-16 10:01:13', '2017-01-25 05:31:13');
INSERT INTO `library_reader_resource` VALUES(27, 1, 1, 11646, 'take', '', '2017-01-16 10:01:47', '2017-01-16 10:01:47', '2017-01-25 05:31:47');
INSERT INTO `library_reader_resource` VALUES(28, 1, 1, 11646, 'take', '', '2017-01-16 10:01:48', '2017-01-16 10:01:48', '2017-01-25 05:31:48');
INSERT INTO `library_reader_resource` VALUES(29, 1, 1, 11646, 'take', '', '2017-01-16 10:06:16', '2017-01-16 10:06:16', '2017-01-25 05:36:16');
INSERT INTO `library_reader_resource` VALUES(30, 1, 1, 11646, 'take', '', '2017-01-16 10:07:43', '2017-01-16 10:07:43', '2017-01-25 05:37:43');
INSERT INTO `library_reader_resource` VALUES(31, 1, 1, 11646, 'take', '', '2017-01-16 10:07:44', '2017-01-16 10:07:44', '2017-01-25 05:37:44');
INSERT INTO `library_reader_resource` VALUES(32, 1, 1, 11646, 'take', '', '2017-01-16 10:07:58', '2017-01-16 10:07:58', '2017-01-25 05:37:58');
INSERT INTO `library_reader_resource` VALUES(33, 1, 1, 11646, 'take', '', '2017-01-17 08:18:38', '2017-01-17 08:18:38', '2017-01-26 03:48:38');
INSERT INTO `library_reader_resource` VALUES(34, 1, 1, 11646, 'take', '', '2017-01-18 08:16:23', '2017-01-18 08:16:23', '2017-01-27 03:46:23');
INSERT INTO `library_reader_resource` VALUES(35, 1, 3, 21421, 'queue', '', '2017-01-16 01:56:28', '2017-01-16 09:56:11', '2017-01-25 05:26:11');
INSERT INTO `library_reader_resource` VALUES(36, 1, 2, 21421, 'queue', '', '2017-01-16 17:56:11', '2017-01-16 09:56:11', '2017-01-25 05:26:11');

--
-- Индексы сохранённых таблиц
--

--
-- Индексы таблицы `library_reader`
--
ALTER TABLE `library_reader`
  ADD PRIMARY KEY (`id`) USING BTREE,
  ADD UNIQUE KEY `library_reader` (`library_id`,`id`) USING BTREE;

--
-- Индексы таблицы `library_reader_resource`
--
ALTER TABLE `library_reader_resource`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_library_reader_resource_library_reader` (`library_reader_id`),
  ADD KEY `resource_id` (`resource_id`);

--
-- AUTO_INCREMENT для сохранённых таблиц
--

--
-- AUTO_INCREMENT для таблицы `library_reader`
--
ALTER TABLE `library_reader`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;
--
-- AUTO_INCREMENT для таблицы `library_reader_resource`
--
ALTER TABLE `library_reader_resource`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;
--
-- Ограничения внешнего ключа сохраненных таблиц
--

--
-- Ограничения внешнего ключа таблицы `library_reader`
--
ALTER TABLE `library_reader`
  ADD CONSTRAINT `fk_library_reader_library` FOREIGN KEY (`library_id`) REFERENCES `library` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Ограничения внешнего ключа таблицы `library_reader_resource`
--
ALTER TABLE `library_reader_resource`
  ADD CONSTRAINT `fk_library_reader_resource_library_reader` FOREIGN KEY (`library_reader_id`) REFERENCES `library_reader` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
