CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantity` (
	dated date NOT NULL,
	itemFk int(11) NOT NULL,
	quantity decimal(10,2) NOT NULL,
	campaign varchar(100) NOT NULL,
	CONSTRAINT itemCampaignQuantity_pk PRIMARY KEY (dated,itemFk),
	CONSTRAINT itemCampaignQuantity_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;

CREATE TABLE IF NOT EXISTS `vn`.`itemCampaignQuantityConfig` (
	id int(10) unsigned NOT NULL PRIMARY KEY,
	defaultCampaign varchar(100) NOT NULL COMMENT 'Campaña por defecto si se le pasa NULL',
	previousDaysToInsert int(10) unsigned NOT NULL COMMENT 'Días anteriores a la fecha de fin de campaña para insertar',
	CONSTRAINT `itemCampaignQuantityConfig_check` CHECK (`id` = 1)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;

INSERT IGNORE INTO `vn`.`itemCampaignQuantityConfig` (id, defaultCampaign, previousDaysToInsert)
	VALUES (1, 'allSaints', 90);
