CREATE TABLE IF NOT EXISTS `extraplancompany` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `maincompany_id` int(11) DEFAULT NULL,
  `agency_id` int(11) DEFAULT NULL,
  `extraplan_id` int(11) DEFAULT NULL,
  `planmerchant` varchar(255) DEFAULT NULL,
  `creationdate` datetime NOT NULL,
  `updatedate` datetime NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `count` int(11) NOT NULL DEFAULT 0,
  `purchased` int(11) NOT NULL DEFAULT 0,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `backactions` tinyint(1) NOT NULL DEFAULT 0,
  `logs` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_extraplancompany_maincompany` (`maincompany_id`),
  KEY `idx_extraplancompany_agency` (`agency_id`),
  KEY `idx_extraplancompany_extraplan` (`extraplan_id`),
  CONSTRAINT `fk_extraplancompany_maincompany`
    FOREIGN KEY (`maincompany_id`) REFERENCES `maincompany` (`id`)
    ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_extraplancompany_agency`
    FOREIGN KEY (`agency_id`) REFERENCES `agency` (`id`)
    ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_extraplancompany_extraplan`
    FOREIGN KEY (`extraplan_id`) REFERENCES `extraplan` (`id`)
    ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
