Commit fd4cd3e5 by Jose Antonio

Issue #200, column in table student

parent 46eab3b8
......@@ -289,6 +289,7 @@ CREATE TABLE IF NOT EXISTS `student` (
`lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`attributes` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Attributes describing student along with his/her configuration',
`id_off` int(11) DEFAULT NULL,
`id_active_scene` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
KEY `id_off` (`id_off`)
......@@ -441,7 +442,6 @@ COMMENT="This table stores working session information. Every working session is
CREATE TABLE IF NOT EXISTS `scene` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`active` boolean NOT NULL DEFAULT 0,
`categories` boolean NOT NULL DEFAULT 0,
`id_sup` int(11) DEFAULT NULL,
`id_stu` int(11) NOT NULL,
......@@ -451,11 +451,6 @@ CREATE TABLE IF NOT EXISTS `scene` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="Scene table information. Every scene is related to some stu_pictos";
CREATE TABLE IF NOT EXISTS `scene_aux`(
`id_stu` int(11) NOT NULL,
`id_scene` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
COMMENT="Aux table to use with triggers-enrolments-integrity-constraints when create a new student";
-- CREATE INDEX ix_ws_begin ON working_session (`begin`);
--
......
......@@ -48,7 +48,7 @@ BEGIN
SET LID = LAST_INSERT_ID();
UPDATE student SET attributes = JSON_SET(attributes, "$.id_active_scene",LID) WHERE id=_id_stu;
UPDATE student SET id_active_scene = LID WHERE id=_id_stu;
UPDATE `stu_picto`
SET `id_scene` = LID
......
......@@ -50,35 +50,19 @@ thisTrigger: BEGIN
END IF;
-- Load core collection for student
INSERT INTO scene (id_stu,id_sup,name,categories) VALUES (new.id, null, 'with_categories', TRUE);
INSERT INTO scene (id_stu,id_sup,name,categories) VALUES (NEW.id, null, 'with_categories', TRUE);
SET LID = LAST_INSERT_ID();
CALL scene_create_core(LID,new.id);
INSERT INTO scene_aux (id_stu,id_scene) VALUES (new.id, LID);
END;;
DROP PROCEDURE IF EXISTS NEW_STUDENT_AUX;
CREATE PROCEDURE NEW_STUDENT_AUX()
BEGIN
DECLARE _id_stu INT;
DECLARE _id_scene INT;
DECLARE done INT DEFAULT FALSE;
DECLARE aux CURSOR FOR SELECT * FROM pictodb.scene_aux;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN aux;
read_loop: LOOP
FETCH aux INTO _id_stu, _id_scene;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE student SET attributes = JSON_SET(attributes, '$.id_active_scene',_id_scene) WHERE id=_id_stu;
DROP PROCEDURE IF EXISTS active_scene_update;
CREATE PROCEDURE active_scene_update(IN _id_stu INTEGER)
BEGIN
DECLARE _id_scene INTEGER;
END LOOP;
CLOSE aux;
DELETE FROM scene_aux;
SELECT id INTO _id_scene FROM scene WHERE id_stu=_id_stu LIMIT 1;
UPDATE student SET id_active_scene=_id_scene WHERE id=_id_stu;
END;;
-- Procedure to add core when new scene is created
......
......@@ -15,22 +15,13 @@ Changes to be performed manually in servers to upgrade
- Delete active column from scene table (deleted from `already done in dev` sql `create scene table` statement)
`alter table scene drop active;`
- Alter table scene to add ON DELETE CASCADE constraint
`ALTER TABLE `scene` ADD CONSTRAINT `stu_scene_fk` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`) ON DELETE CASCADE;`
- Create aux table for scene
`CREATE TABLE IF NOT EXISTS `scene_aux`(
`id_stu` int(11) NOT NULL,
`id_scene` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
COMMENT="Aux table to use with triggers-enrolments-integrity-constraints when create a new student";`
- Add id_active_scene to student table
`ALTER TABLE student ADD COLUMN id_active_scene INT(11) DEFAULT NULL;`
`ALTER TABLE student ADD CONSTRAINT fk_active_scene FOREIGN KEY (`id_active_scene`) REFERENCES scene (`id`);`
- Reload enrolments trigger
`source /vagrant/roles/database/files/triggers-enrolments-integrity-constraints.sql;`
To Do only in PRE:
- Load scene_adapt
`source /vagrant/roles/database/files/scene_adapt.sql`
(already done in dev)
......
......@@ -187,9 +187,6 @@ module.exports = {
Student.create(params)
.then(function(created) {
Scene.query('CALL NEW_STUDENT_AUX() ',[], function(err, result) {
});
sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created));
License.activate(params.license_number, created.id, function(err, license) {
if (err)
......@@ -830,7 +827,7 @@ module.exports = {
if (typeof req.params.id_stu == 'undefined' || !req.params.id_stu)
return res.badRequest("id_stu not defined");
Student.findOne({id:req.params.id_stu}).then(function(student){
Scene.findOne({id: student.attributes.id_active_scene})
Scene.findOne({id: student.id_active_scene})
.then(function(scene){
if(!scene)
return res.badRequest("Scene not found");
......@@ -860,7 +857,7 @@ module.exports = {
var params = req.allParams();
Student.findOne({id:params.id_stu})
.then(student => {
student.attributes.id_active_scene=params.id_scene;
student.id_active_scene=params.id_scene;
delete student.password;
student.save(function(error){
if(error){
......@@ -891,7 +888,7 @@ module.exports = {
return res.serverError("No scenes found");
}else{
scenes.forEach(function(scene, cb){
scene.active = scene.id == student.attributes.id_active_scene;
scene.active = scene.id == student.id_active_scene;
});
return res.ok(scenes);
}
......
......@@ -73,6 +73,12 @@ module.exports = {
required: false,
model: 'Office'
},
id_active_scene: {
columnName: 'id_active_scene',
type: 'integer',
required: false,
model: 'Scene'
},
// Relación con StuSup
stuSup: {
collection: 'stusup',
......@@ -259,6 +265,19 @@ module.exports = {
attrs.pic = sails.config.pictogram.paths.defaultAvatarFileName;
next();
},
/**
* Call a stored procedure to update the active scene of the student
* @param {Object} student All student properties to be stored
* @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed
* to the function if necesary)
*/
afterCreate: function(student, next) {
Student.query('CALL active_scene_update(?) ',[student.id], function(err, result) {
sails.log.debug('call to active_scene_update stored procedure after create student');
});
next();
},
/**
* Checks the given properties before updating a new Student
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment