text: -- phpMyAdmin SQL Dump
  -- version 4.0.10deb1
  -- http://www.phpmyadmin.net
  --
  -- Хост: localhost
  -- Время создания: Дек 12 2015 г., 16:20
  -- Версия сервера: 5.5.46-0ubuntu0.14.04.2
  -- Версия PHP: 5.5.9-1ubuntu4.14
  
  SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  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 utf8 */;
  
  --
  -- База данных: `mobidev`
  --
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `item`
  --
  
  CREATE TABLE IF NOT EXISTS `item` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `category_id` int(11) DEFAULT NULL,
    `title` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
    `cost` double NOT NULL,
    `image` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`),
    KEY `category_id` (`category_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ;
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `item_cat`
  --
  
  CREATE TABLE IF NOT EXISTS `item_cat` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `orders`
  --
  
  CREATE TABLE IF NOT EXISTS `orders` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `user_id` int(11) NOT NULL,
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `user_id` (`user_id`),
    KEY `id` (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `order_item`
  --
  
  CREATE TABLE IF NOT EXISTS `order_item` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `item_id` int(11) NOT NULL,
    `order_id` int(11) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `item_id` (`item_id`),
    KEY `order_id` (`order_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `user`
  --
  
  CREATE TABLE IF NOT EXISTS `user` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
    `mail` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
    `city` varchar(50) COLLATE utf8_unicode_ci NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;
  
  -- --------------------------------------------------------
  
  --
  -- Структура таблицы `vote`
  --
  
  CREATE TABLE IF NOT EXISTS `vote` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `item_id` int(11) NOT NULL,
    `user_id` int(11) DEFAULT NULL,
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `text` text COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`),
    KEY `item_id` (`item_id`),
    KEY `user_id` (`user_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  
  --
  -- Ограничения внешнего ключа сохраненных таблиц
  --
  
  --
  -- Ограничения внешнего ключа таблицы `item`
  --
  ALTER TABLE `item`
    ADD CONSTRAINT `item_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `item_cat` (`id`) ON DELETE SET NULL;
  
  --
  -- Ограничения внешнего ключа таблицы `orders`
  --
  ALTER TABLE `orders`
    ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
  
  --
  -- Ограничения внешнего ключа таблицы `order_item`
  --
  ALTER TABLE `order_item`
    ADD CONSTRAINT `order_item_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`),
    ADD CONSTRAINT `order_item_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`);
  
  --
  -- Ограничения внешнего ключа таблицы `vote`
  --
  ALTER TABLE `vote`
    ADD CONSTRAINT `vote_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE CASCADE,
    ADD CONSTRAINT `vote_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL;
  
  /*!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 */;
  