diff --git a/CRM/Civirules/Form/RuleAction.php b/CRM/Civirules/Form/RuleAction.php
index 69593dd2c154ebd97b9ab2cec346e8bddc8dcdcf..d75d78b0e2cc26faebca87cb28c11aab146c8e36 100644
--- a/CRM/Civirules/Form/RuleAction.php
+++ b/CRM/Civirules/Form/RuleAction.php
@@ -71,7 +71,6 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
    * @access public
    */
   function postProcess() {
-
     $saveParams = array(
       'rule_id' => $this->_submitValues['rule_id'],
       'action_id' => $this->_submitValues['rule_action_select'],
diff --git a/CRM/Civirules/Upgrader.php b/CRM/Civirules/Upgrader.php
index 67725534860ee42e1e31ffeff9b6fe88bb9988b7..8b28104f51f7d2d86eed63edc39880d00ea237f4 100755
--- a/CRM/Civirules/Upgrader.php
+++ b/CRM/Civirules/Upgrader.php
@@ -54,11 +54,7 @@ class CRM_Civirules_Upgrader extends CRM_Civirules_Upgrader_Base {
     }
     // rename columns event_id and event_params in civirule_rule
     if (CRM_Core_DAO::checkTableExists("civirule_rule")) {
-      CRM_Core_DAO::executeQuery("ALTER TABLE civirule_rule CHANGE event_id trigger_id INT");
-      CRM_Core_DAO::executeQuery("ALTER TABLE civirule_rule CHANGE event_params trigger_params TEXT");
+      $this->executeSqlFile('sql/upgrade1002.sql');
     }
-    // remove index on event_id and add one on trigger_id
-    CRM_Core_DAO("ALTER TABLE civirule_rule ADD INDEX fk_rule_trigger_idx (trigger_id),
-      DROP INDEX fk_rule_event_idx");
   }
 }
\ No newline at end of file
diff --git a/sql/update1002.sql b/sql/update1002.sql
new file mode 100644
index 0000000000000000000000000000000000000000..0469ebce9804f186e15771945902e00c1bbe1d03
--- /dev/null
+++ b/sql/update1002.sql
@@ -0,0 +1,6 @@
+ALTER TABLE civirule_rule DROP INDEX fk_rule_event_idx;
+ALTER TABLE civirule_rule CHANGE event_id trigger_id INT UNSIGNED;
+ALTER TABLE civirule_rule CHANGE event_params trigger_params TEXT;
+ALTER TABLE civirule_rule ADD CONSTRAINT fk_rule_trigger
+  FOREIGN KEY (trigger_id) REFERENCES civirule_trigger(id);
+ALTER TABLE civirule_rule ADD INDEX fk_rule_trigger_idx (trigger_id);