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

START TRANSACTION;



--
-- Database: `cstiker_schedule`
--

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

--
-- Table structure for table `courses`
--

CREATE TABLE `courses` (
  `course_id` int(10) UNSIGNED NOT NULL,
  `course_code` varchar(32) NOT NULL,
  `course_title` varchar(128) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `courses`
--

INSERT INTO `courses` (`course_id`, `course_code`, `course_title`) VALUES
(1, 'ACAD-324', 'The Practice of Design'),
(2, 'ACAD-325', 'Human-Technology Interaction'),
(3, 'ACAD-276', 'Dev II'),
(4, 'IDSN-599', 'Social Media Incubator'),
(5, 'ACAD-406', 'Purpose-Driven Incubator');

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

--
-- Table structure for table `locations`
--

CREATE TABLE `locations` (
  `location_id` int(10) UNSIGNED NOT NULL,
  `building_code` varchar(16) NOT NULL,
  `room` varchar(32) NOT NULL,
  `display_name` varchar(64) GENERATED ALWAYS AS (concat(`building_code`,' ',`room`)) STORED
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `locations`
--

INSERT INTO `locations` (`location_id`, `building_code`, `room`) VALUES
(2, 'IYH', '210'),
(1, 'IYH', '212/213');

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

--
-- Table structure for table `meetings`
--

CREATE TABLE `meetings` (
  `meeting_id` bigint(20) UNSIGNED NOT NULL,
  `meeting_date` date NOT NULL,
  `start_time` time NOT NULL,
  `end_time` time NOT NULL,
  `course_id` int(10) UNSIGNED NOT NULL,
  `location_id` int(10) UNSIGNED NOT NULL,
  `meeting_type_id` tinyint(3) UNSIGNED NOT NULL,
  `notes` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `meetings`
--

INSERT INTO `meetings` (`meeting_id`, `meeting_date`, `start_time`, `end_time`, `course_id`, `location_id`, `meeting_type_id`, `notes`) VALUES
(1, '2025-09-15', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(2, '2025-09-16', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(3, '2025-09-16', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(4, '2025-09-17', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(5, '2025-09-17', '14:00:00', '15:50:00', 4, 1, 1, NULL),
(6, '2025-09-17', '18:00:00', '19:50:00', 5, 2, 3, NULL),
(7, '2025-09-18', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(8, '2025-09-18', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(9, '2025-09-22', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(10, '2025-09-23', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(11, '2025-09-23', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(12, '2025-09-24', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(13, '2025-09-24', '14:00:00', '15:50:00', 4, 1, 1, NULL),
(14, '2025-09-24', '18:00:00', '19:50:00', 5, 2, 3, NULL),
(15, '2025-09-25', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(16, '2025-09-25', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(17, '2025-09-29', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(18, '2025-09-30', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(19, '2025-09-30', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(20, '2025-10-01', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(21, '2025-10-01', '14:00:00', '15:50:00', 4, 1, 1, NULL),
(22, '2025-10-01', '18:00:00', '19:50:00', 5, 2, 3, NULL),
(23, '2025-10-02', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(24, '2025-10-02', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(25, '2025-10-06', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(26, '2025-10-07', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(27, '2025-10-07', '14:00:00', '15:50:00', 3, 2, 3, NULL),
(28, '2025-10-08', '10:00:00', '11:50:00', 1, 1, 1, NULL),
(29, '2025-10-08', '14:00:00', '15:50:00', 4, 1, 1, NULL),
(30, '2025-10-08', '18:00:00', '19:50:00', 5, 2, 3, NULL),
(31, '2025-10-09', '12:00:00', '13:50:00', 2, 1, 1, NULL),
(32, '2025-10-09', '14:00:00', '15:50:00', 3, 2, 3, NULL);

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

--
-- Table structure for table `meeting_types`
--

CREATE TABLE `meeting_types` (
  `meeting_type_id` tinyint(3) UNSIGNED NOT NULL,
  `type_name` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `meeting_types`
--

INSERT INTO `meeting_types` (`meeting_type_id`, `type_name`) VALUES
(2, 'Lab'),
(1, 'Lecture'),
(3, 'Lecture/Lab');

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

--
-- Stand-in structure for view `vw_full_schedule`
-- (See below for the actual view)
--
CREATE TABLE `vw_full_schedule` (
`meeting_id` bigint(20) unsigned
,`meeting_date` varchar(10)
,`start_time` varchar(8)
,`end_time` varchar(8)
,`location` varchar(64)
,`meeting_type` varchar(32)
,`course` varchar(162)
);

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

--
-- Structure for view `vw_full_schedule`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`cstiker`@`localhost` SQL SECURITY DEFINER VIEW `vw_full_schedule`  AS SELECT `m`.`meeting_id` AS `meeting_id`, date_format(`m`.`meeting_date`,'%m/%d/%Y') AS `meeting_date`, time_format(`m`.`start_time`,'%h:%i %p') AS `start_time`, time_format(`m`.`end_time`,'%h:%i %p') AS `end_time`, `l`.`display_name` AS `location`, `t`.`type_name` AS `meeting_type`, concat(`c`.`course_code`,': ',`c`.`course_title`) AS `course` FROM (((`meetings` `m` join `courses` `c` on((`c`.`course_id` = `m`.`course_id`))) join `locations` `l` on((`l`.`location_id` = `m`.`location_id`))) join `meeting_types` `t` on((`t`.`meeting_type_id` = `m`.`meeting_type_id`))) ORDER BY `m`.`meeting_date` ASC, `m`.`start_time` ASC, `c`.`course_code` ASC ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `courses`
--
ALTER TABLE `courses`
  ADD PRIMARY KEY (`course_id`),
  ADD UNIQUE KEY `uq_course_code` (`course_code`);

--
-- Indexes for table `locations`
--
ALTER TABLE `locations`
  ADD PRIMARY KEY (`location_id`),
  ADD UNIQUE KEY `uq_location` (`building_code`,`room`);

--
-- Indexes for table `meetings`
--
ALTER TABLE `meetings`
  ADD PRIMARY KEY (`meeting_id`),
  ADD KEY `ix_meeting_date` (`meeting_date`),
  ADD KEY `fk_meetings_course` (`course_id`),
  ADD KEY `fk_meetings_location` (`location_id`),
  ADD KEY `fk_meetings_type` (`meeting_type_id`);

--
-- Indexes for table `meeting_types`
--
ALTER TABLE `meeting_types`
  ADD PRIMARY KEY (`meeting_type_id`),
  ADD UNIQUE KEY `uq_type` (`type_name`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `courses`
--
ALTER TABLE `courses`
  MODIFY `course_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `locations`
--
ALTER TABLE `locations`
  MODIFY `location_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `meetings`
--
ALTER TABLE `meetings`
  MODIFY `meeting_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33;

--
-- AUTO_INCREMENT for table `meeting_types`
--
ALTER TABLE `meeting_types`
  MODIFY `meeting_type_id` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `meetings`
--
ALTER TABLE `meetings`
  ADD CONSTRAINT `fk_meetings_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`),
  ADD CONSTRAINT `fk_meetings_location` FOREIGN KEY (`location_id`) REFERENCES `locations` (`location_id`),
  ADD CONSTRAINT `fk_meetings_type` FOREIGN KEY (`meeting_type_id`) REFERENCES `meeting_types` (`meeting_type_id`);
COMMIT;

