DROP TABLE IF EXISTS `vn`.`userLog`;

CREATE TABLE `account`.`userLog` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `originFk` int(10) unsigned DEFAULT NULL,
  `userFk` int(10) unsigned DEFAULT NULL,
  `action` set('insert','update','delete') COLLATE utf8mb4_unicode_ci NOT NULL,
  `creationDate` timestamp NULL DEFAULT current_timestamp(),
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `changedModel` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `oldInstance` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `newInstance` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `changedModelId` int(11) DEFAULT NULL,
  `changedModelValue` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `originFk` (`originFk`),
  KEY `userFk` (`userFk`),
  CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `account`.`roleLog` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `originFk` int(10) unsigned DEFAULT NULL,
  `userFk` int(10) unsigned DEFAULT NULL,
  `action` set('insert','update','delete') COLLATE utf8mb3_unicode_ci NOT NULL,
  `creationDate` timestamp NULL DEFAULT current_timestamp(),
  `description` text CHARACTER SET utf8mb3 DEFAULT NULL,
  `changedModel` varchar(45) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  `oldInstance` text COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  `newInstance` text COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  `changedModelId` int(11) DEFAULT NULL,
  `changedModelValue` varchar(45) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `originFk` (`originFk`),
  KEY `userFk` (`userFk`),
  CONSTRAINT `roleLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `roleLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;

INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
    VALUES
        ('UserLog', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
        ('RoleLog', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
