-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Gegenereerd op: 04 mrt 2016 om 16:20
-- Serverversie: 5.6.26
-- PHP-versie: 5.6.12

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 utf8mb4 */;

--
-- Database: `ticket_system`
--

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

--
-- Tabelstructuur voor tabel `category_users`
--

CREATE TABLE IF NOT EXISTS `category_users` (
  `cu_id` int(10) unsigned NOT NULL,
  `category_id` int(10) unsigned NOT NULL,
  `user_id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Tabelstructuur voor tabel `item_categories`
--

CREATE TABLE IF NOT EXISTS `item_categories` (
  `category_id` int(10) unsigned NOT NULL,
  `category` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket`
--

CREATE TABLE IF NOT EXISTS `ticket` (
  `ticket_id` int(11) NOT NULL,
  `category` enum('Bug','Malfunction','Question','Feature','Other') NOT NULL,
  `status` enum('New','Open','Pending','Solved','Closed','Rejected') NOT NULL,
  `date_created` int(11) NOT NULL,
  `priority` enum('Low','Medium','High','') DEFAULT NULL,
  `submitted_by` int(11) NOT NULL,
  `assigned_to` int(11) DEFAULT NULL,
  `f303` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket_commentreplies`
--

CREATE TABLE IF NOT EXISTS `ticket_commentreplies` (
  `reply_id` int(11) NOT NULL,
  `comment_id` int(11) DEFAULT NULL,
  `reply` text NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket_comments`
--

CREATE TABLE IF NOT EXISTS `ticket_comments` (
  `comment_id` int(11) NOT NULL,
  `comment` text NOT NULL,
  `comment_user` int(11) unsigned NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket_history`
--

CREATE TABLE IF NOT EXISTS `ticket_history` (
  `id` int(11) NOT NULL,
  `ticket_id` int(11) NOT NULL,
  `comment_id` int(11) DEFAULT NULL,
  `status_date` int(11) NOT NULL,
  `status_old` enum('New','Open','Pending','Solved','Closed','Rejected') DEFAULT NULL,
  `status_new` enum('New','Open','Pending','Solved','Closed','Rejected') DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket_information`
--

CREATE TABLE IF NOT EXISTS `ticket_information` (
  `ticket_id` int(11) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `issue` text NOT NULL,
  `occurance_date` int(11) DEFAULT NULL,
  `occurance_time` varchar(255) DEFAULT NULL,
  `solution` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Tabelstructuur voor tabel `ticket_item`
--

CREATE TABLE IF NOT EXISTS `ticket_item` (
  `ticket_id` int(11) NOT NULL,
  `product_id` varchar(255) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `category_id` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexen voor geëxporteerde tabellen
--

--
-- Indexen voor tabel `category_users`
--
ALTER TABLE `category_users`
  ADD PRIMARY KEY (`cu_id`),
  ADD UNIQUE KEY `category_id` (`category_id`,`user_id`),
  ADD KEY `fk_cu_ic` (`category_id`);

--
-- Indexen voor tabel `item_categories`
--
ALTER TABLE `item_categories`
  ADD PRIMARY KEY (`category_id`);

--
-- Indexen voor tabel `ticket`
--
ALTER TABLE `ticket`
  ADD PRIMARY KEY (`ticket_id`);

--
-- Indexen voor tabel `ticket_commentreplies`
--
ALTER TABLE `ticket_commentreplies`
  ADD PRIMARY KEY (`reply_id`),
  ADD KEY `fk_comment_id` (`comment_id`);

--
-- Indexen voor tabel `ticket_comments`
--
ALTER TABLE `ticket_comments`
  ADD PRIMARY KEY (`comment_id`);

--
-- Indexen voor tabel `ticket_history`
--
ALTER TABLE `ticket_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ticket_fk_ticketid` (`ticket_id`),
  ADD KEY `ticket_fk_commentid` (`comment_id`);

--
-- Indexen voor tabel `ticket_information`
--
ALTER TABLE `ticket_information`
  ADD UNIQUE KEY `ticket_id` (`ticket_id`),
  ADD KEY `ticketinfo_fk_ticketid` (`ticket_id`);

--
-- Indexen voor tabel `ticket_item`
--
ALTER TABLE `ticket_item`
  ADD UNIQUE KEY `ticket_id` (`ticket_id`,`product_id`),
  ADD KEY `item_fk_ticketid` (`ticket_id`),
  ADD KEY `category_id` (`category_id`);

--
-- AUTO_INCREMENT voor geëxporteerde tabellen
--

--
-- AUTO_INCREMENT voor een tabel `category_users`
--
ALTER TABLE `category_users`
  MODIFY `cu_id` int(10) unsigned NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT voor een tabel `item_categories`
--
ALTER TABLE `item_categories`
  MODIFY `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT voor een tabel `ticket`
--
ALTER TABLE `ticket`
  MODIFY `ticket_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT voor een tabel `ticket_commentreplies`
--
ALTER TABLE `ticket_commentreplies`
  MODIFY `reply_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT voor een tabel `ticket_comments`
--
ALTER TABLE `ticket_comments`
  MODIFY `comment_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT voor een tabel `ticket_history`
--
ALTER TABLE `ticket_history`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- Beperkingen voor geëxporteerde tabellen
--

--
-- Beperkingen voor tabel `category_users`
--
ALTER TABLE `category_users`
  ADD CONSTRAINT `fk_cu_ic` FOREIGN KEY (`category_id`) REFERENCES `item_categories` (`category_id`) ON UPDATE CASCADE;

--
-- Beperkingen voor tabel `ticket_commentreplies`
--
ALTER TABLE `ticket_commentreplies`
  ADD CONSTRAINT `fk_comment_id` FOREIGN KEY (`comment_id`) REFERENCES `ticket_comments` (`comment_id`) ON UPDATE CASCADE;

--
-- Beperkingen voor tabel `ticket_history`
--
ALTER TABLE `ticket_history`
  ADD CONSTRAINT `ticket_fk_commentid` FOREIGN KEY (`comment_id`) REFERENCES `ticket_comments` (`comment_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `ticket_fk_ticketid` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`ticket_id`) ON UPDATE CASCADE;

--
-- Beperkingen voor tabel `ticket_information`
--
ALTER TABLE `ticket_information`
  ADD CONSTRAINT `ticketinfo_fk_ticketid` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`ticket_id`) ON UPDATE CASCADE;

--
-- Beperkingen voor tabel `ticket_item`
--
ALTER TABLE `ticket_item`
  ADD CONSTRAINT `item_fk_ticketid` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`ticket_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `ticket_item_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `item_categories` (`category_id`) ON UPDATE CASCADE;

/*!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 */;
