preparing PRE update

parent f24d4ceb
...@@ -95,6 +95,8 @@ CREATE TABLE IF NOT EXISTS `instruction` ( ...@@ -95,6 +95,8 @@ CREATE TABLE IF NOT EXISTS `instruction` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="An instruction is a 'phase' in a method for learning AAC"; COMMENT="An instruction is a 'phase' in a method for learning AAC";
-- CREATE INDEX ix_instruction_begin ON instruction (`begin`);
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -396,6 +398,7 @@ CREATE TABLE IF NOT EXISTS `try` ( ...@@ -396,6 +398,7 @@ CREATE TABLE IF NOT EXISTS `try` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table contains tries information (they belong to a working session)"; COMMENT="This table contains tries information (they belong to a working session)";
-- CREATE INDEX ix_try_begin ON try (`begin`);
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
...@@ -427,6 +430,7 @@ CREATE TABLE IF NOT EXISTS `working_session` ( ...@@ -427,6 +430,7 @@ CREATE TABLE IF NOT EXISTS `working_session` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table stores working session information. Every working session is related to one instruction and one supervisor (and the instruction is related to one method which is related to one student)"; COMMENT="This table stores working session information. Every working session is related to one instruction and one supervisor (and the instruction is related to one method which is related to one student)";
-- CREATE INDEX ix_ws_begin ON working_session (`begin`);
-- --
-- Restricciones para tablas volcadas -- Restricciones para tablas volcadas
-- --
......
...@@ -12,7 +12,7 @@ module.exports = { ...@@ -12,7 +12,7 @@ module.exports = {
autoPK : false, autoPK : false,
autoCreatedAt : false, autoCreatedAt : false,
autoUpdatedAt : false, autoUpdatedAt : false,
attributes: { attributes: {
id: { id: {
type: "integer", type: "integer",
...@@ -43,13 +43,13 @@ module.exports = { ...@@ -43,13 +43,13 @@ module.exports = {
size: 1024 size: 1024
} }
}, },
afterUpdate: function (attrs, next) { afterUpdate: function (attrs, next) {
StuOpenTry.findOne({id_ws: attrs.workingSession}).exec(function(err, stuopentry) { StuOpenTry.findOne({id_ws: attrs.workingSession}).exec(function(err, stuopentry) {
if (err) if (err)
throw new Error("Error at"+attrs.workingSession+"("+err+")"); throw new Error("Error at"+attrs.workingSession+"("+err+")");
if (stuopentry) if (stuopentry)
attrs.next_try_id=stuopentry.openTry; attrs.next_try_id=stuopentry.openTry;
next(); next();
}); });
} }
} }
\ No newline at end of file
...@@ -79,14 +79,16 @@ module.exports = { ...@@ -79,14 +79,16 @@ module.exports = {
next(err); next(err);
}) })
}, },
afterCreate: function (attrs, next) { afterCreate: function (attrs, next) {
// stu_opentry table is updated when a new try is inserted in try table
StuOpenTry.findOne({id_ws: attrs.id}).exec(function(err, stuopentry) { // (which is, itself, fired by a new session insertion)
// see triggers-sessions-integrity-constraints.sql
StuOpenTry.findOne({id_ws: attrs.id}).exec(function(err, stuopentry) {
if (err || !stuopentry) if (err || !stuopentry)
throw new Error("No try found at"+attrs.id+"("+err+")"); throw new Error("No try found at"+attrs.id+"("+err+")");
attrs.first_try_id=stuopentry.openTry; attrs.first_try_id=stuopentry.openTry;
next(); next();
}); });
}, },
// //
......
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