-- MySQL Workbench Synchronization
-- Generated: 2018-11-14 08:25
-- Model: New Model
-- Version: 1.0
-- Project: Name of the project
-- Author: Steven Heath



CREATE TABLE IF NOT EXISTS `news_article_image` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `image_id` INT(11) NOT NULL,
  `news_article_id` INT(11) NOT NULL,
  `type` INT(11) NOT NULL DEFAULT 0 COMMENT '0 - Hero\n1 - Thumbnail\n2 - Sponsor',
  PRIMARY KEY (`id`),
  INDEX `fk_news_article_image_image1_idx` (`image_id` ASC),
  INDEX `fk_news_article_image_news_article1_idx` (`news_article_id` ASC),
  CONSTRAINT `fk_news_article_image_image1`
    FOREIGN KEY (`image_id`)
    REFERENCES `image` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_news_article_image_news_article1`
    FOREIGN KEY (`news_article_id`)
    REFERENCES `news_article` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;


INSERT INTO news_article_image (image_id, news_article_id, type)
	SELECT image_id, id as news_article_id, 0 as type
	FROM news_article;


ALTER TABLE `news_article`
DROP FOREIGN KEY `fk_news_article_image1`;


ALTER TABLE `news_article`
DROP COLUMN `image_id`,
DROP INDEX `fk_news_article_image1_idx` ;


