forge->addField([ 'RuleID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], 'Name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], 'Description' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'EventCode' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false], 'ScopeType' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => false, 'default' => 'GLOBAL'], 'TestSiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => true], 'ConditionExpr' => ['type' => 'VARCHAR', 'constraint' => 1000, 'null' => true], 'Priority' => ['type' => 'INT', 'null' => true, 'default' => 100], 'Active' => ['type' => 'TINYINT', 'constraint' => 1, 'null' => true, 'default' => 1], 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'StartDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('RuleID', true); $this->forge->addKey('EventCode'); $this->forge->addKey('ScopeType'); $this->forge->addKey('TestSiteID'); $this->forge->createTable('ruledef'); // Optional scope FK (only when ScopeType=TESTSITE) $this->db->query('ALTER TABLE `ruledef` ADD CONSTRAINT `fk_ruledef_testsite` FOREIGN KEY (`TestSiteID`) REFERENCES `testdefsite`(`TestSiteID`) ON DELETE CASCADE ON UPDATE CASCADE'); // ruleaction $this->forge->addField([ 'RuleActionID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], 'RuleID' => ['type' => 'INT', 'unsigned' => true, 'null' => false], 'Seq' => ['type' => 'INT', 'null' => true, 'default' => 1], 'ActionType' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false], 'ActionParams' => ['type' => 'TEXT', 'null' => true], 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('RuleActionID', true); $this->forge->addKey('RuleID'); $this->forge->createTable('ruleaction'); $this->db->query('ALTER TABLE `ruleaction` ADD CONSTRAINT `fk_ruleaction_ruledef` FOREIGN KEY (`RuleID`) REFERENCES `ruledef`(`RuleID`) ON DELETE CASCADE ON UPDATE CASCADE'); } public function down() { $this->forge->dropTable('ruleaction'); $this->forge->dropTable('ruledef'); } }