/*
 EMDT-599 audit log migration
 add new columns to avoid reference to Users table,
 one-off population of new columns.
 Moulya
 21 May 2019
 MySQL version
 */



alter table AUDIT_LOG add audit_user_username varchar(256) null;
alter table AUDIT_LOG add audit_user_fullname varchar(512) null;

UPDATE AUDIT_LOG t1
    INNER JOIN users t2 ON t1.audit_user_id = t2.user_id
SET t1.audit_user_username = t2.user_username;

UPDATE AUDIT_LOG t1
    INNER JOIN users t2 ON t1.audit_user_id = t2.user_id
SET t1.audit_user_fullname =trim(concat(trim(concat(trim(concat(trim(concat(t2.user_prefix,' ',t2.user_forename)),' ',t2.user_middlename)),' ',t2.user_surname)),' ',t2.user_suffix))