26 lines
932 B
SQL
26 lines
932 B
SQL
CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` (
|
|
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
|
dated date NOT NULL,
|
|
itemFk int(11) NOT NULL,
|
|
quantity decimal(10,2) NOT NULL,
|
|
total decimal(10,2) NOT NULL,
|
|
campaign varchar(100) NOT NULL,
|
|
UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`),
|
|
CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE
|
|
)
|
|
ENGINE=InnoDB
|
|
DEFAULT CHARSET=utf8mb3
|
|
COLLATE=utf8mb3_unicode_ci
|
|
COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.';
|
|
|
|
ALTER TABLE vn.campaign
|
|
ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign';
|
|
|
|
UPDATE vn.campaign
|
|
SET previousDays = 90
|
|
WHERE code = 'allSaints';
|
|
|
|
UPDATE vn.campaign
|
|
SET previousDays = 60
|
|
WHERE code IN ('valentinesDay', 'mothersDay');
|