DROP TABLE IF EXISTS event_slug_history;


CREATE TABLE IF NOT EXISTS `slug_history` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `slug` VARCHAR(100) NOT NULL,
    `update_date` DATETIME NULL DEFAULT '0000-00-00 00:00:00',
    `slug_type` INT NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`)
);



CREATE TABLE IF NOT EXISTS `event_slug_history` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `slug_history_id` INT NOT NULL,
    `event_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_event_slug_history_slug_history_idx` (`slug_history_id` ASC),
    INDEX `fk_event_slug_history_event_idx` (`event_id` ASC),
    CONSTRAINT `fk_event_slug_history_slug_history`
    FOREIGN KEY (`slug_history_id`)
    REFERENCES `slug_history` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    CONSTRAINT `fk_event_slug_history_event`
    FOREIGN KEY (`event_id`)
    REFERENCES `event` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);



CREATE TABLE IF NOT EXISTS `news_article_slug_history` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `slug_history_id` INT NOT NULL,
    `news_article_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_news_article_slug_history_slug_history_idx` (`slug_history_id` ASC),
    INDEX `fk_news_article_slug_history_news_article_idx` (`news_article_id` ASC),
    CONSTRAINT `fk_news_article_slug_history_slug_history`
    FOREIGN KEY (`slug_history_id`)
    REFERENCES `slug_history` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    CONSTRAINT `fk_news_article_slug_history_news_article`
    FOREIGN KEY (`news_article_id`)
    REFERENCES `news_article` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);



CREATE TABLE IF NOT EXISTS `page_slug_history` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `slug_history_id` INT NOT NULL,
    `page_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_page_slug_history_slug_history_idx` (`slug_history_id` ASC),
    INDEX `fk_page_slug_history_page_idx` (`page_id` ASC),
    CONSTRAINT `fk_page_slug_history_slug_history`
    FOREIGN KEY (`slug_history_id`)
    REFERENCES `slug_history` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    CONSTRAINT `fk_page_slug_history_page`
    FOREIGN KEY (`page_id`)
    REFERENCES `page` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);



