-- DeployRule table (formerly CopyPasteRule)
CREATE TABLE IF NOT EXISTS `DeployRule`
(
    `id`            INT(11)         NOT NULL AUTO_INCREMENT,
    `name`          VARCHAR(100)    UNIQUE NOT NULL,
    `definition`    TEXT            NOT NULL DEFAULT '',
    `description`   VARCHAR(255)    NOT NULL DEFAULT '',
    `modified`      DATETIME        NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
    `created`       DATETIME        NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (`id`)
    )
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8
    AUTO_INCREMENT = 0;

-- DeployRef table - tracks deployed records between databases
CREATE TABLE IF NOT EXISTS `DeployRef`
(
    `id`            INT(11)         NOT NULL AUTO_INCREMENT,
    `tableName`     VARCHAR(100)    NOT NULL,
    `srcId`         INT(11)         NOT NULL COMMENT 'Source record ID from export',
    `targetId`      INT(11)         NOT NULL COMMENT 'Target record ID from import',
    `content`       TEXT            DEFAULT NULL COMMENT 'JSON data of record from export (for skipModified mode)',
    `ruleId`        INT(11)         DEFAULT NULL COMMENT 'DeployRule ID used for deployment',
    `potentiallyDeleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Flag: srcId not in last export, possibly deleted on source',
    `modified`      DATETIME        NOT NULL COMMENT 'Modified timestamp of imported record',
    `created`       DATETIME        NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (`id`),
    UNIQUE KEY `tableNameSrcIdRuleId` (`tableName`, `srcId`, `ruleId`),
    KEY `tableNameTargetId` (`tableName`, `targetId`),
    KEY `ruleId` (`ruleId`)
    )
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8
    AUTO_INCREMENT = 0;