<?php
/*
* Adding a field to the `recurringfee` table
*/
$query = "ALTER TABLE `recurringfee` "
        ."ADD `recurring` TINYINT(4) DEFAULT NULL "
        ."AFTER `status` ";
$result = $this->db->query($query);

/*
* Search all the `domains`
*/
$query = "SELECT d.`id`, "
        ."d.`recurring` "
        ."FROM `domains` d "
        ."WHERE IFNULL(`recurring`, 0) != 0 "
        ."ORDER BY d.`id` ";
$result = $this->db->query($query);





while ($row = $result->fetch()) {
    /*
    * Update in `recurringfee` with `billingtypeid` = -1 [BILLINGTYPE_PACKAGE]
      set `recurring` with the value in `domains`.`recurring`
    */
    $query2 = "UPDATE `recurringfee` "
             ."SET `recurring` = ? "
             ."WHERE `appliestoid` = ? "
             ."AND `billingtypeid` = -1 ";
    $result2 = $this->db->query(
        $query2,
        $row['recurring'],
        $row['id']
    );
}

/*
* Drop old field
*/
$query = "ALTER TABLE `domains` "
        ."DROP `recurring` ";
$result = $this->db->query($query);
?>