-- +--------------------------------------------------------------------+
-- | 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
-- *
-- *******************************************************/



-- /*******************************************************
-- *
-- * Create new tables
-- *
-- *******************************************************/

-- /*******************************************************
-- *
-- * civirule_action
-- *
-- * CiviRules Actions
-- *
-- *******************************************************/
CREATE TABLE `civirule_action` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Action ID',
  `name` varchar(80) DEFAULT NULL,
  `label` varchar(128) DEFAULT NULL,
  `class_name` varchar(128) DEFAULT NULL,
  `is_active` tinyint NOT NULL DEFAULT 1,
  `created_date` date DEFAULT NULL,
  `created_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `modified_date` date DEFAULT NULL,
  `modified_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  PRIMARY KEY (`id`)
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_condition
-- *
-- * CiviRules conditions
-- *
-- *******************************************************/
CREATE TABLE `civirule_condition` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Condition ID',
  `name` varchar(80) DEFAULT NULL,
  `label` varchar(128) DEFAULT NULL,
  `class_name` varchar(128) DEFAULT NULL,
  `is_active` tinyint NOT NULL DEFAULT 1,
  `created_date` date DEFAULT NULL,
  `created_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `modified_date` date DEFAULT NULL,
  `modified_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  PRIMARY KEY (`id`)
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_trigger
-- *
-- * CiviRules Rule Triggers
-- *
-- *******************************************************/
CREATE TABLE `civirule_trigger` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Trigger ID',
  `name` varchar(80) DEFAULT NULL,
  `label` varchar(128) DEFAULT NULL,
  `object_name` varchar(45) DEFAULT NULL,
  `op` varchar(45) DEFAULT NULL,
  `cron` tinyint DEFAULT 0,
  `class_name` varchar(128) DEFAULT NULL,
  `is_active` tinyint NOT NULL DEFAULT 1,
  `created_date` date DEFAULT NULL,
  `created_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `modified_date` date DEFAULT NULL,
  `modified_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  PRIMARY KEY (`id`)
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_rule
-- *
-- * CiviRules Rule
-- *
-- *******************************************************/
CREATE TABLE `civirule_rule` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Rule ID',
  `name` varchar(80) DEFAULT NULL,
  `label` varchar(128) DEFAULT NULL,
  `trigger_id` int unsigned DEFAULT NULL,
  `trigger_params` text DEFAULT NULL,
  `is_active` tinyint NOT NULL DEFAULT 1,
  `description` varchar(255) DEFAULT NULL,
  `help_text` text DEFAULT NULL,
  `created_date` date DEFAULT NULL COMMENT 'When was this item created',
  `created_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `modified_date` date DEFAULT NULL COMMENT 'When was this item modified',
  `modified_user_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `is_debug` tinyint DEFAULT 0,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civirule_rule_trigger_id FOREIGN KEY (`trigger_id`) REFERENCES `civirule_trigger`(`id`) ON DELETE NO ACTION,
  CONSTRAINT FK_civirule_rule_created_user_id FOREIGN KEY (`created_user_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL,
  CONSTRAINT FK_civirule_rule_modified_user_id FOREIGN KEY (`modified_user_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_rule_action
-- *
-- * CiviRules Rule Actions
-- *
-- *******************************************************/
CREATE TABLE `civirule_rule_action` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique RuleAction ID',
  `rule_id` int unsigned DEFAULT NULL,
  `action_id` int unsigned DEFAULT NULL,
  `action_params` text DEFAULT NULL,
  `delay` text DEFAULT NULL,
  `ignore_condition_with_delay` int DEFAULT 0,
  `is_active` tinyint NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civirule_rule_action_rule_id FOREIGN KEY (`rule_id`) REFERENCES `civirule_rule`(`id`) ON DELETE CASCADE,
  CONSTRAINT FK_civirule_rule_action_action_id FOREIGN KEY (`action_id`) REFERENCES `civirule_action`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_rule_condition
-- *
-- * CiviRules Rule Conditions
-- *
-- *******************************************************/
CREATE TABLE `civirule_rule_condition` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique RuleCondition ID',
  `rule_id` int unsigned,
  `condition_link` varchar(3) DEFAULT NULL,
  `condition_id` int unsigned,
  `condition_params` text DEFAULT NULL,
  `is_active` tinyint NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civirule_rule_condition_rule_id FOREIGN KEY (`rule_id`) REFERENCES `civirule_rule`(`id`) ON DELETE CASCADE,
  CONSTRAINT FK_civirule_rule_condition_condition_id FOREIGN KEY (`condition_id`) REFERENCES `civirule_condition`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_rule_log
-- *
-- * CiviRules Rule Logs
-- *
-- *******************************************************/
CREATE TABLE `civirule_rule_log` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique RuleLog ID',
  `rule_id` int unsigned DEFAULT NULL,
  `contact_id` int unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `entity_table` varchar(255) DEFAULT NULL,
  `entity_id` int unsigned DEFAULT NULL,
  `log_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `rule_id`(rule_id),
  INDEX `contact_id`(contact_id),
  INDEX `rule_contact_id`(rule_id, contact_id),
  CONSTRAINT FK_civirule_rule_log_rule_id FOREIGN KEY (`rule_id`) REFERENCES `civirule_rule`(`id`) ON DELETE SET NULL,
  CONSTRAINT FK_civirule_rule_log_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * civirule_rule_tag
-- *
-- * Tags for CiviRules rule
-- *
-- *******************************************************/
CREATE TABLE `civirule_rule_tag` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'CiviRules Rule Tags',
  `rule_id` int unsigned DEFAULT NULL,
  `rule_tag_id` int unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT FK_civirule_rule_tag_rule_id FOREIGN KEY (`rule_id`) REFERENCES `civirule_rule`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;
