CREATE TABLE `vn`.campaign
(
	id INT AUTO_INCREMENT,
	code ENUM('mothersDay', 'allSaints', 'valentinesDay') NOT NULL,
	dated DATE DEFAULT CURDATE() NOT NULL,
    scopeDays INT NOT NULL DEFAULT '15',
	CONSTRAINT campaign_pk
		PRIMARY KEY (id)
);

CREATE UNIQUE INDEX campaign_dated_uindex
	ON `vn`.campaign (dated);

-- TODOS SANTOS
INSERT INTO `vn`.campaign(code, dated)
SELECT 'allSaints' AS code, dated
    FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
    AND month = 11
    AND day = 1;

-- SAN VALENTIN
INSERT INTO `vn`.campaign(code, dated)
SELECT 'valentinesDay' AS code, dated
    FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
    AND month = 2
    AND day = 14;

-- DIA DE LA MADRE
INSERT INTO `vn`.campaign(code, dated)
SELECT 'mothersDay' AS code, dated
    FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
    AND month = 5
    AND WEEK(dated, 5) - WEEK(DATE_SUB(dated, INTERVAL DAYOFMONTH(dated) - 1 DAY), 5) + 1 = 1 -- WEEK OF MONTH
    AND DAYOFWEEK(dated) = 1;
