28 lines
920 B
SQL
28 lines
920 B
SQL
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 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.id,
|
|
`userFk` = account.myUser_getId();
|
|
END$$
|
|
DELIMITER ;
|