-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `mingjiny_schedule`
--

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

--
-- Table structure for table `activity_type`
--

CREATE TABLE `activity_type` (
  `type_id` int(11) NOT NULL,
  `type_name` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `activity_type`
--

INSERT INTO `activity_type` (`type_id`, `type_name`) VALUES
(1, 'Lab'),
(2, 'Lecture'),
(3, 'Club'),
(4, 'Project');

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

--
-- Table structure for table `course`
--

CREATE TABLE `course` (
  `template_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `number` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `course`
--

INSERT INTO `course` (`template_id`, `name`, `number`) VALUES
(1, 'DEV II', 'ACAD 276'),
(2, 'The Practice of Design', 'ACAD 324'),
(3, 'History of Science', 'HIST 251'),
(4, 'Humans and Their Environment', 'BISC 102'),
(5, 'Physical Product Design', 'IDSN 524'),
(6, 'Formula Electric', 'AME 491');

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

--
-- Table structure for table `course_section`
--

CREATE TABLE `course_section` (
  `template_type_id` int(11) NOT NULL,
  `template_id` int(11) NOT NULL,
  `type_id` int(11) NOT NULL,
  `code` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `course_section`
--

INSERT INTO `course_section` (`template_type_id`, `template_id`, `type_id`, `code`) VALUES
(1, 1, 2, '10242'),
(2, 2, 2, '10249'),
(3, 3, 2, '37029'),
(4, 3, 1, '37026'),
(5, 4, 2, '13000'),
(6, 4, 1, '13106'),
(7, 5, 2, '34077'),
(8, 6, 3, NULL);

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

--
-- Stand-in structure for view `detailed_event_schedule`
-- (See below for the actual view)
--
CREATE TABLE `detailed_event_schedule` (
`event_id` int(11)
,`date_id` int(11)
,`event_date` date
,`start_time` time
,`end_time` time
,`course_name` varchar(100)
,`course_number` varchar(10)
,`activity_type` varchar(50)
,`section_code` varchar(20)
,`room` varchar(50)
,`meeting_purpose` varchar(25)
);

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

--
-- Table structure for table `event_occurrence`
--

CREATE TABLE `event_occurrence` (
  `date_id` int(11) NOT NULL,
  `event_id` int(11) NOT NULL,
  `event_date` date NOT NULL,
  `start_time` time DEFAULT NULL,
  `end_time` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `event_occurrence`
--

INSERT INTO `event_occurrence` (`date_id`, `event_id`, `event_date`, `start_time`, `end_time`) VALUES
(12, 2, '2025-09-08', NULL, NULL),
(13, 2, '2025-09-15', NULL, NULL),
(14, 2, '2025-09-22', NULL, NULL),
(15, 2, '2025-09-29', NULL, NULL),
(16, 2, '2025-09-10', NULL, NULL),
(17, 2, '2025-09-17', NULL, NULL),
(18, 2, '2025-09-24', NULL, NULL),
(19, 2, '2025-10-01', NULL, NULL),
(20, 3, '2025-09-09', NULL, NULL),
(21, 3, '2025-09-16', NULL, NULL),
(22, 3, '2025-09-23', NULL, NULL),
(23, 3, '2025-09-30', NULL, NULL),
(24, 3, '2025-09-11', NULL, NULL),
(25, 3, '2025-09-18', NULL, NULL),
(26, 3, '2025-09-25', NULL, NULL),
(27, 3, '2025-10-02', NULL, NULL),
(28, 4, '2025-09-12', NULL, NULL),
(29, 4, '2025-09-19', NULL, NULL),
(30, 4, '2025-09-26', NULL, NULL),
(31, 4, '2025-10-03', NULL, NULL),
(32, 5, '2025-09-09', NULL, NULL),
(33, 5, '2025-09-16', NULL, NULL),
(34, 5, '2025-09-23', NULL, NULL),
(35, 5, '2025-09-30', NULL, NULL),
(36, 5, '2025-09-11', NULL, NULL),
(37, 5, '2025-09-18', NULL, NULL),
(38, 5, '2025-09-25', NULL, NULL),
(39, 5, '2025-10-02', NULL, NULL),
(40, 6, '2025-09-09', NULL, NULL),
(41, 6, '2025-09-16', NULL, NULL),
(42, 6, '2025-09-23', NULL, NULL),
(43, 6, '2025-09-30', NULL, NULL),
(44, 1, '2025-09-09', NULL, NULL),
(45, 1, '2025-09-16', NULL, NULL),
(46, 1, '2025-09-23', NULL, NULL),
(47, 1, '2025-09-30', NULL, NULL),
(48, 1, '2025-09-11', NULL, NULL),
(49, 1, '2025-09-18', NULL, NULL),
(50, 1, '2025-09-25', NULL, NULL),
(51, 1, '2025-10-02', NULL, NULL),
(52, 7, '2025-09-09', NULL, NULL),
(53, 7, '2025-09-16', NULL, NULL),
(54, 7, '2025-09-23', NULL, NULL),
(55, 7, '2025-09-30', NULL, NULL),
(56, 8, '2025-09-08', NULL, NULL),
(57, 8, '2025-09-15', NULL, NULL),
(58, 8, '2025-09-22', NULL, NULL),
(59, 8, '2025-09-29', NULL, NULL),
(60, 9, '2025-09-08', NULL, NULL),
(61, 9, '2025-09-15', NULL, NULL),
(62, 9, '2025-09-22', NULL, NULL),
(63, 9, '2025-09-29', NULL, NULL),
(64, 9, '2025-09-12', NULL, NULL),
(65, 9, '2025-09-19', NULL, NULL),
(66, 9, '2025-09-26', NULL, NULL),
(67, 9, '2025-10-03', NULL, NULL),
(68, 10, '2025-09-08', NULL, NULL),
(69, 10, '2025-09-15', NULL, NULL),
(70, 10, '2025-09-22', NULL, NULL),
(71, 10, '2025-09-29', NULL, NULL);

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

--
-- Table structure for table `meeting_purpose`
--

CREATE TABLE `meeting_purpose` (
  `purpose_id` int(11) NOT NULL,
  `purpose` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `meeting_purpose`
--

INSERT INTO `meeting_purpose` (`purpose_id`, `purpose`) VALUES
(1, 'Design Review'),
(2, 'Systems Meeting'),
(3, 'Leads Meeting');

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

--
-- Table structure for table `room`
--

CREATE TABLE `room` (
  `location_id` int(11) NOT NULL,
  `name` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `room`
--

INSERT INTO `room` (`location_id`, `name`) VALUES
(1, 'IYH 210'),
(2, 'THH 102'),
(3, 'THH 121'),
(4, 'ZHS 257'),
(5, 'IYH 110'),
(6, 'KAP 140'),
(7, 'BFMS');

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

--
-- Table structure for table `scheduled_event`
--

CREATE TABLE `scheduled_event` (
  `event_id` int(11) NOT NULL,
  `template_id` int(11) NOT NULL,
  `type_id` int(11) NOT NULL,
  `purpose_id` int(11) DEFAULT NULL,
  `location_id` int(11) DEFAULT NULL,
  `start_time` time NOT NULL,
  `end_time` time NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `scheduled_event`
--

INSERT INTO `scheduled_event` (`event_id`, `template_id`, `type_id`, `purpose_id`, `location_id`, `start_time`, `end_time`) VALUES
(1, 1, 2, NULL, 1, '00:14:00', '00:15:50'),
(2, 2, 2, NULL, 1, '10:00:00', '11:50:00'),
(3, 3, 2, NULL, 2, '08:00:00', '09:20:00'),
(4, 3, 1, NULL, 3, '08:00:00', '09:20:00'),
(5, 4, 2, NULL, 2, '09:30:00', '10:50:00'),
(6, 4, 1, NULL, 4, '16:00:00', '17:50:00'),
(7, 5, 2, NULL, 5, '17:00:00', '19:50:00'),
(8, 6, 3, 1, 6, '17:00:00', '18:30:00'),
(9, 6, 3, 2, 7, '18:00:00', '20:00:00'),
(10, 6, 3, 3, 7, '20:00:00', '21:00:00');

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

--
-- Stand-in structure for view `start_time_view`
-- (See below for the actual view)
--
CREATE TABLE `start_time_view` (
`start_time` time
);

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

--
-- Structure for view `detailed_event_schedule`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`mingjiny`@`%` SQL SECURITY DEFINER VIEW `detailed_event_schedule`  AS SELECT `eo`.`event_id` AS `event_id`, `eo`.`date_id` AS `date_id`, `eo`.`event_date` AS `event_date`, coalesce(`eo`.`start_time`,`se`.`start_time`) AS `start_time`, coalesce(`eo`.`end_time`,`se`.`end_time`) AS `end_time`, `c`.`name` AS `course_name`, `c`.`number` AS `course_number`, `at`.`type_name` AS `activity_type`, `cs`.`code` AS `section_code`, `r`.`name` AS `room`, `mp`.`purpose` AS `meeting_purpose` FROM ((((((`event_occurrence` `eo` join `scheduled_event` `se` on((`eo`.`event_id` = `se`.`event_id`))) join `course` `c` on((`se`.`template_id` = `c`.`template_id`))) join `activity_type` `at` on((`se`.`type_id` = `at`.`type_id`))) left join `course_section` `cs` on(((`cs`.`template_id` = `se`.`template_id`) and (`cs`.`type_id` = `se`.`type_id`)))) left join `room` `r` on((`se`.`location_id` = `r`.`location_id`))) left join `meeting_purpose` `mp` on((`se`.`purpose_id` = `mp`.`purpose_id`))) ORDER BY `eo`.`event_date` ASC, coalesce(`eo`.`start_time`,`se`.`start_time`) ASC, `c`.`name` ASC ;

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

--
-- Structure for view `start_time_view`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`mingjiny`@`%` SQL SECURITY DEFINER VIEW `start_time_view`  AS SELECT `scheduled_event`.`start_time` AS `start_time` FROM `scheduled_event` ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `activity_type`
--
ALTER TABLE `activity_type`
  ADD PRIMARY KEY (`type_id`);

--
-- Indexes for table `course`
--
ALTER TABLE `course`
  ADD PRIMARY KEY (`template_id`);

--
-- Indexes for table `course_section`
--
ALTER TABLE `course_section`
  ADD PRIMARY KEY (`template_type_id`),
  ADD KEY `template_id` (`template_id`),
  ADD KEY `type_id` (`type_id`);

--
-- Indexes for table `event_occurrence`
--
ALTER TABLE `event_occurrence`
  ADD PRIMARY KEY (`date_id`),
  ADD KEY `event_id` (`event_id`);

--
-- Indexes for table `meeting_purpose`
--
ALTER TABLE `meeting_purpose`
  ADD PRIMARY KEY (`purpose_id`);

--
-- Indexes for table `room`
--
ALTER TABLE `room`
  ADD PRIMARY KEY (`location_id`);

--
-- Indexes for table `scheduled_event`
--
ALTER TABLE `scheduled_event`
  ADD PRIMARY KEY (`event_id`),
  ADD KEY `template_id` (`template_id`),
  ADD KEY `type_id` (`type_id`),
  ADD KEY `purpose_id` (`purpose_id`),
  ADD KEY `location_id` (`location_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `activity_type`
--
ALTER TABLE `activity_type`
  MODIFY `type_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `course`
--
ALTER TABLE `course`
  MODIFY `template_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT for table `course_section`
--
ALTER TABLE `course_section`
  MODIFY `template_type_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT for table `event_occurrence`
--
ALTER TABLE `event_occurrence`
  MODIFY `date_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=72;

--
-- AUTO_INCREMENT for table `meeting_purpose`
--
ALTER TABLE `meeting_purpose`
  MODIFY `purpose_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `room`
--
ALTER TABLE `room`
  MODIFY `location_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `scheduled_event`
--
ALTER TABLE `scheduled_event`
  MODIFY `event_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `course_section`
--
ALTER TABLE `course_section`
  ADD CONSTRAINT `course_section_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `course` (`template_id`),
  ADD CONSTRAINT `course_section_ibfk_2` FOREIGN KEY (`type_id`) REFERENCES `activity_type` (`type_id`);

--
-- Constraints for table `event_occurrence`
--
ALTER TABLE `event_occurrence`
  ADD CONSTRAINT `event_occurrence_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `scheduled_event` (`event_id`);

--
-- Constraints for table `scheduled_event`
--
ALTER TABLE `scheduled_event`
  ADD CONSTRAINT `scheduled_event_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `course` (`template_id`),
  ADD CONSTRAINT `scheduled_event_ibfk_2` FOREIGN KEY (`type_id`) REFERENCES `activity_type` (`type_id`),
  ADD CONSTRAINT `scheduled_event_ibfk_3` FOREIGN KEY (`purpose_id`) REFERENCES `meeting_purpose` (`purpose_id`),
  ADD CONSTRAINT `scheduled_event_ibfk_4` FOREIGN KEY (`location_id`) REFERENCES `room` (`location_id`);
COMMIT;

