-- +--------------------------------------------------------------------+
-- | Copyright CiviCRM LLC. All rights reserved.                        |
-- |                                                                    |
-- | This work is published under the GNU AGPLv3 license with some      |
-- | permitted exceptions and without any warranty. For full license    |
-- | and copyright information, see https://civicrm.org/licensing       |
-- +--------------------------------------------------------------------+
--
-- Generated from schema.tpl
-- DO NOT EDIT.  Generated by CRM_Core_CodeGen
--
-- /*******************************************************
-- *
-- * Clean up the existing tables - this section generated from drop.tpl
-- *
-- *******************************************************/

SET FOREIGN_KEY_CHECKS=0;

DROP TABLE IF EXISTS `civicrm_data_processor_source`;
DROP TABLE IF EXISTS `civicrm_data_processor_output`;
DROP TABLE IF EXISTS `civicrm_data_processor_filter`;
DROP TABLE IF EXISTS `civicrm_data_processor_filter_collection`;
DROP TABLE IF EXISTS `civicrm_data_processor_field`;
DROP TABLE IF EXISTS `civicrm_data_processor`;

SET FOREIGN_KEY_CHECKS=1;
-- /*******************************************************
-- *
-- * Create new tables
-- *
-- *******************************************************/

-- /*******************************************************
-- *
-- * civicrm_data_processor
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessor ID',
  `name` varchar(255) NULL,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `configuration` text NULL,
  `is_active` tinyint NOT NULL,
  `description` text NULL,
  `storage_type` varchar(255) NULL,
  `storage_configuration` text NULL,
  `status` int unsigned NULL DEFAULT 0,
  `source_file` varchar(255) NULL,
  PRIMARY KEY (`id`)
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civicrm_data_processor_field
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor_field` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorField ID',
  `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor',
  `weight` int NULL,
  `name` varchar(255) NULL,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `configuration` text NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civicrm_data_processor_field_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civicrm_data_processor_filter_collection
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor_filter_collection` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorFilterCollection ID',
  `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor',
  `weight` int NULL,
  `name` varchar(255) NULL,
  `title` varchar(255) NOT NULL,
  `description` text NULL,
  `condition` varchar(255) NULL DEFAULT 'AND',
  `link_condition` varchar(255) NULL DEFAULT 'AND',
  `show_collapsed` tinyint NOT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civicrm_data_processor_filter_collection_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civicrm_data_processor_filter
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor_filter` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorFilter ID',
  `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor',
  `weight` int NULL,
  `name` varchar(255) NULL,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `is_required` tinyint NULL,
  `is_exposed` tinyint NULL DEFAULT 1,
  `configuration` text NULL,
  `filter_value` text NULL,
  `collection_id` int unsigned,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civicrm_data_processor_filter_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE,
  CONSTRAINT FK_civicrm_data_processor_filter_collection_id FOREIGN KEY (`collection_id`) REFERENCES `civicrm_data_processor_filter_collection`(`id`) ON DELETE SET NULL
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civicrm_data_processor_output
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor_output` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorOutput ID',
  `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor',
  `type` varchar(255) NOT NULL,
  `configuration` text NULL,
  `permission` varchar(255) NULL,
  `api_entity` varchar(255) NULL,
  `api_action` varchar(255) NULL,
  `api_count_action` varchar(255) NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civicrm_data_processor_output_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civicrm_data_processor_source
-- *
-- *******************************************************/
CREATE TABLE `civicrm_data_processor_source` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorSource ID',
  `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor',
  `weight` int NULL,
  `name` varchar(255) NULL,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `configuration` text NULL,
  `join_type` varchar(255) NULL,
  `join_configuration` text NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civicrm_data_processor_source_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;
