salix/db/versions/.archive/10470-notaUltimoUsuario/00-firstScript.sql

15 lines
513 B
SQL

ALTER TABLE `vn`.`entry` ADD observationEditorFk INT(10) unsigned NULL COMMENT 'Último usuario que ha modificado el campo evaNotes';
ALTER TABLE `vn`.`entry` ADD CONSTRAINT entry_observationEditorFk FOREIGN KEY (observationEditorFk) REFERENCES account.user(id) ON UPDATE CASCADE;
UPDATE
`vn`.`entry` e
SET
observationEditorFk = (
SELECT w.userFk
FROM
`vn`.`worker` w
JOIN `account`.`user` u ON
u.id = w.userFk
WHERE
w.code = RIGHT(e.evaNotes,3)),
evaNotes = LEFT(evaNotes,LENGTH(evaNotes)-5)