Skip to content
Snippets Groups Projects
Commit 5e976a93 authored by PavelBegunkov's avatar PavelBegunkov
Browse files

structure preparation

parent 266d122a
Branches
Tags
No related merge requests found
......@@ -364,13 +364,11 @@ CREATE TABLE IF NOT EXISTS `specializations` (
CREATE TABLE IF NOT EXISTS `students` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`GroupID` int(11) NOT NULL,
`AccountID` int(11) NOT NULL,
`LastName` varchar(30) CHARACTER SET utf8 NOT NULL,
`FirstName` varchar(30) CHARACTER SET utf8 NOT NULL,
`SecondName` varchar(30) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `GroupID` (`GroupID`),
KEY `AccountID` (`AccountID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
......@@ -516,6 +514,27 @@ CREATE TABLE IF NOT EXISTS `recovery_tokens` (
-- --------------------------------------------------------
--
-- Структура таблицы `students_groups`
--
CREATE TABLE IF NOT EXISTS `students_groups` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`StudentID` int(11) NOT NULL,
`GroupID` int(11) NOT NULL,
`SemesterID` int(11) NOT NULL,
`IsStudyLeave` tinyint(1) NOT NULL DEFAULT '0',
`Date` date NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `StudentID_2` (`StudentID`,`GroupID`,`SemesterID`),
KEY `SemesterID` (`SemesterID`),
KEY `StudentID` (`StudentID`),
KEY `GroupID` (`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы `user_roles`
--
......@@ -674,7 +693,6 @@ ALTER TABLE `specializations`
-- Ограничения внешнего ключа таблицы `students`
--
ALTER TABLE `students`
ADD CONSTRAINT `students_ibfk_1` FOREIGN KEY (`GroupID`) REFERENCES `study_groups` (`ID`),
ADD CONSTRAINT `students_ibfk_2` FOREIGN KEY (`AccountID`) REFERENCES `accounts` (`ID`);
--
......@@ -707,6 +725,15 @@ ALTER TABLE `subjects_faculties`
ADD CONSTRAINT `subjects_faculties_ibfk_2` FOREIGN KEY (`SubjectID`) REFERENCES `subjects` (`ID`);
--
-- Ограничения внешнего ключа таблицы `students_groups`
--
ALTER TABLE `students_groups`
ADD CONSTRAINT `students_groups_ibfk_1` FOREIGN KEY (`StudentID`) REFERENCES `students` (`ID`),
ADD CONSTRAINT `students_groups_ibfk_2` FOREIGN KEY (`GroupID`) REFERENCES `study_groups` (`ID`),
ADD CONSTRAINT `students_groups_ibfk_3` FOREIGN KEY (`SemesterID`) REFERENCES `semesters` (`ID`);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
......
ALTER TABLE `disciplines` CHANGE LectionCount LectureCount int(11) NOT NULL DEFAULT '0';
# 5.03.15 - db refactoring
ALTER TABLE `disciplines` CHANGE LectionCount LectureCount int(11) NOT NULL DEFAULT '0';
ALTER TABLE students DROP FOREIGN KEY students_ibfk_1;
ALTER TABLE disciplines_groups DROP FOREIGN KEY disciplines_groups_ibfk_2;
......@@ -41,3 +41,42 @@ SET modules.OrderNum = 3141592
WHERE modules.OrderNum = 3141692;
# 15.03.15 - student's groups memorization
CREATE TABLE IF NOT EXISTS `students_groups` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`StudentID` int(11) NOT NULL,
`GroupID` int(11) NOT NULL,
`SemesterID` int(11) NOT NULL,
`IsStudyLeave` tinyint(1) NOT NULL DEFAULT '0',
`Date` date NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `StudentID_2` (`StudentID`,`GroupID`,`SemesterID`),
KEY `SemesterID` (`SemesterID`),
KEY `StudentID` (`StudentID`),
KEY `GroupID` (`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# constraints
ALTER TABLE `students_groups`
ADD CONSTRAINT `students_groups_ibfk_1` FOREIGN KEY (`StudentID`) REFERENCES `students` (`ID`),
ADD CONSTRAINT `students_groups_ibfk_2` FOREIGN KEY (`GroupID`) REFERENCES `study_groups` (`ID`),
ADD CONSTRAINT `students_groups_ibfk_3` FOREIGN KEY (`SemesterID`) REFERENCES `semesters` (`ID`);
# save groups
INSERT INTO `students_groups` (StudentID, GroupID, SemesterID)
SELECT DISTINCT students.ID, students.GroupID, semesters.ID
FROM `students`
CROSS JOIN `semesters`;
# clear useless data
ALTER TABLE `students` DROP FOREIGN KEY `students_ibfk_1` ;
ALTER TABLE `students` DROP INDEX `GroupID` ;
ALTER TABLE `students` DROP `GroupID` ;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment