ALTER TABLE `cpm_asset`
DROP `type`;

ALTER TABLE `cpm_device_type`
ADD `add_to_declaration` int NOT NULL DEFAULT '0' AFTER `fk_type`;

ALTER TABLE `cpm_device_type`
ADD `add_to_declaration_cold` int NOT NULL AFTER `add_to_declaration`;

CREATE TABLE `cpm_asset_declaration` (
  `id_asset_declaration` int NOT NULL AUTO_INCREMENT,
  `fk_asset` int NOT NULL,
  `type` enum('hot','cold') NOT NULL,
  `data` json NOT NULL,
  PRIMARY KEY (`id_asset_declaration`)
);


DROP TABLE IF EXISTS `cpm_pdf`;
CREATE TABLE `cpm_pdf` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `code` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT INTO `cpm_pdf` (`id`, `name`, `code`) VALUES (1,	'Controllo fumi',	'controllo_fumi');


ALTER TABLE `cpm_maintenance_setting`
ADD `fk_pdf` int NULL;


CREATE TABLE `cpm_maintenance_work` (
  `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `fk_device` int NOT NULL,
  `modules_data` json NOT NULL,
  `date` date NOT NULL,
  `start_hour` time NOT NULL,
  `end_hour` time NOT NULL,
  `fk_user` int NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (`fk_user`) REFERENCES `cpm_user` (`id`)
);

CREATE TABLE `cpm_maintenance_work_has_maintenance` (
  `id_maintenance_work` int NOT NULL,
  `id_maintenance` int NOT NULL
);

DD `is_autority` int NULL DEFAULT '1',
ADD `office_autority` varchar(255) NULL AFTER `is_autority`,
ADD `adress_autority` varchar(255) NULL AFTER `office_autority`,
ADD `fk_city_autority` varchar(255) NULL AFTER `adress_autority`;

ALTER TABLE `cpm_asset`
ADD `name_autority` varchar(255) NULL AFTER `is_autority`;

ALTER TABLE `cpm_asset`
ADD `cap_autority` varchar(5) COLLATE 'utf8mb4_0900_ai_ci' NULL;