USE vn;
ALTER TABLE `vn`.`labelReport` 
        RENAME TO  `vn`.`report` ;
		
UPDATE `vn`.`report` SET `name` = 'invoice' WHERE (`id` = '3');
UPDATE `vn`.`report` SET `name` = 'cleanDMS' WHERE (`id` = '11');
UPDATE `vn`.`report` SET `name` = 'invoicePdf' WHERE (`id` = '40');

		
CREATE TABLE `printQueue` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `printerFk` tinyint(3) unsigned DEFAULT NULL,
  `priorityFk` tinyint(3) unsigned DEFAULT NULL,
  `reportFk` tinyint(3) unsigned DEFAULT NULL,
  `statusCode` enum('queued','error','printing') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued',
  `started` datetime DEFAULT NULL,
  `finished` datetime DEFAULT NULL,
  `workerFk` int(11) DEFAULT NULL,
  `error` text COLLATE utf8_unicode_ci,
  `errorNumber` int(11) DEFAULT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `statusCode` (`statusCode`),
  KEY `printerFk` (`printerFk`),
  KEY `priorityFk` (`priorityFk`),
  KEY `workerFk` (`workerFk`),
  KEY `printQueue_report` (`reportFk`),
  CONSTRAINT `printQueue_priorityFk` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `printQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `printQueue_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;




CREATE TABLE `printQueueArgs` (
  `printQueueFk` int(10) unsigned NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  KEY `printQueueArgs_printQueueFk_idx` (`printQueueFk`),
  CONSTRAINT `printQueueArgs_printQueueFk` FOREIGN KEY (`printQueueFk`) REFERENCES `printQueue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Argumentos que se pasarán al informe para generarlos';



ALTER TABLE `vn`.`sector` 
	DROP FOREIGN KEY `sector_labelReport`;

ALTER TABLE `vn`.`sector` 
	CHANGE COLUMN `labelReportFk` `reportFk` TINYINT(3) UNSIGNED NULL DEFAULT NULL ;

ALTER TABLE `vn`.`sector` 
	ADD CONSTRAINT `sector_report`
	FOREIGN KEY (`reportFk`)
	REFERENCES `vn`.`report` (`id`);

ALTER TABLE `vn`.`queuePriority` 
ADD COLUMN `code` VARCHAR(6) NULL AFTER `priority`;

UPDATE `vn`.`queuePriority` SET `code` = 'normal' WHERE (`id` = '2');
UPDATE `vn`.`queuePriority` SET `code` = 'low' WHERE (`id` = '3');
UPDATE `vn`.`queuePriority` SET `code` = 'high' WHERE (`id` = '1');

