Merge pull request 'fixes #5749 Añadir clave primaria autoincrementable a la tabla vn.zoneIncluded' (!1590) from 5749-autoincrement-zoneIncluded into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1590 Reviewed-by: Alex Moreno <alexm@verdnatura.es> Reviewed-by: Juan Ferrer <juan@verdnatura.es>
This commit is contained in:
commit
68975e0412
|
@ -0,0 +1,26 @@
|
||||||
|
ALTER TABLE `vn`.`zoneIncluded`
|
||||||
|
ADD COLUMN `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
|
||||||
|
DROP PRIMARY KEY,
|
||||||
|
DROP FOREIGN KEY `zoneFk2`,
|
||||||
|
DROP FOREIGN KEY `zoneGeoFk2`,
|
||||||
|
DROP KEY `geoFk_idx`,
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD CONSTRAINT `zoneIncluded_FK_1` FOREIGN KEY (zoneFk) REFERENCES `vn`.`zone`(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT `zoneIncluded_FK_2` FOREIGN KEY (geoFk) REFERENCES `vn`.`zoneGeo`(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT `unique_zone_geo` UNIQUE (`zoneFk`, `geoFk`);
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
|
||||||
|
AFTER DELETE ON `zoneIncluded`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO zoneLog
|
||||||
|
SET `action` = 'delete',
|
||||||
|
`changedModel` = 'zoneIncluded',
|
||||||
|
`changedModelId` = OLD.zoneFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -30,18 +30,21 @@ module.exports = Self => {
|
||||||
Self.toggleIsIncluded = async(id, geoId, isIncluded, options) => {
|
Self.toggleIsIncluded = async(id, geoId, isIncluded, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (isIncluded === undefined)
|
if (isIncluded === undefined)
|
||||||
return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
|
return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
|
||||||
else {
|
|
||||||
return models.ZoneIncluded.upsert({
|
const zoneIncluded = await models.ZoneIncluded.findOne({where: {zoneFk: id, geoFk: geoId}}, myOptions);
|
||||||
|
|
||||||
|
if (zoneIncluded)
|
||||||
|
return zoneIncluded.updateAttribute('isIncluded', isIncluded, myOptions);
|
||||||
|
|
||||||
|
return models.ZoneIncluded.create({
|
||||||
zoneFk: id,
|
zoneFk: id,
|
||||||
geoFk: geoId,
|
geoFk: geoId,
|
||||||
isIncluded: isIncluded
|
isIncluded: isIncluded
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"zoneFk": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue