/*
 * OrangeHRM Enterprise is a closed sourced comprehensive Human Resource Management (HRM)
 * System that captures all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM Inc is the owner of the patent, copyright, trade secrets, trademarks and any
 * other intellectual property rights which subsist in the Licensed Materials. OrangeHRM Inc
 * is the owner of the media / downloaded OrangeHRM Enterprise software files on which the
 * Licensed Materials are received. Title to the Licensed Materials and media shall remain
 * vested in OrangeHRM Inc. For the avoidance of doubt title and all intellectual property
 * rights to any design, new software, new protocol, new interface, enhancement, update,
 * derivative works, revised screen text or any other items that OrangeHRM Inc creates for
 * Customer shall remain vested in OrangeHRM Inc. Any rights not expressly granted herein are
 * reserved to OrangeHRM Inc.
 *
 * Please refer http://www.orangehrm.com/Files/OrangeHRM_Commercial_License.pdf for the license which includes terms and conditions on using this software.
 *
 */

create table ohrm_dynamic_form_version
(
    `id`                int unsigned not null auto_increment,
    `name`              varchar(100) not null,
    `description`       varchar(500) default null,
    `endpoint`          varchar(250) not null,
    `action`            varchar(32)  default null,
    `meta_data`         json         default null,
    `data_group_id`     int          default null,
    `created_by`        int          default null,
    `updated_by`        int          default null,
    `created_by_name`   varchar(200) default null,
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `deleted_at` DATETIME DEFAULT NULL,
    `dynamic_form_id` int unsigned not null,
    `version` int default 1,
    CONSTRAINT `fk_ohrm_dynamic_form_version_created_by` FOREIGN KEY (`created_by`) REFERENCES `ohrm_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT `fk_ohrm_dynamic_form_version_updated_by` FOREIGN KEY (`updated_by`) REFERENCES `ohrm_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT `fk_ohrm_dynamic_form_version_data_group_id` FOREIGN KEY (`data_group_id`) REFERENCES `ohrm_data_group` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT `fk_ohrm_dynamic_form_version_dynamic_form_id` FOREIGN KEY (`dynamic_form_id`) REFERENCES `ohrm_dynamic_form` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
    primary key (`id`)
) engine = innodb default charset = utf8;


ALTER TABLE `ohrm_token_section`
    ADD CONSTRAINT `fk_token_section_dynamic_form` FOREIGN KEY (`dynamic_form_version_id`) REFERENCES `ohrm_dynamic_form_version` (`id`);
