function up()
{
$CI =& get_instance();
$CI->load->dbforge();
if ($CI->db->field_exists('article_id', 'article2cat')) {
$fields = array('article_id' => array('name' => 'article_id_rel', 'type' => 'int', 'constraint' => '20'));
$CI->dbforge->modify_column('article2cat', $fields);
$fields = array('category_id' => array('name' => 'category_id_rel', 'type' => 'int', 'constraint' => '20'));
$CI->dbforge->modify_column('article2cat', $fields);
}
if (!$CI->db->field_exists('cat_image', 'categories')) {
// Get all the users
$CI->db->from('categories');
$query = $CI->db->get();
// Drop the table
$CI->dbforge->drop_table('categories');
// Now recreate it
$fields = array('cat_id' => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE));
$CI->dbforge->add_field($fields);
$CI->dbforge->add_field("cat_parent int(11) NOT NULL default '0'");
$CI->dbforge->add_field("cat_uri varchar(255) NOT NULL default '0'");
$CI->dbforge->add_field("cat_name varchar(55) NOT NULL default ''");
$CI->dbforge->add_field("cat_keywords varchar(55) NOT NULL default ''");
$CI->dbforge->add_field("cat_image varchar(55) NOT NULL");
$CI->dbforge->add_field("cat_description text NOT NULL");
$CI->dbforge->add_field("cat_allowads ENUM('no','yes') NOT NULL DEFAULT 'yes'");
$CI->dbforge->add_field("cat_display ENUM('no','yes') NOT NULL DEFAULT 'yes'");
$CI->dbforge->add_field("cat_order int(11) NOT NULL default '0'");
$CI->dbforge->add_field("cat_promo text NOT NULL");
$CI->dbforge->add_field("cat_views int(11) NOT NULL default '0'");
$CI->dbforge->add_key('cat_id', TRUE);
$CI->dbforge->add_key('cat_uri', TRUE);
$CI->dbforge->add_key('cat_name');
$CI->dbforge->add_key('cat_parent');
$CI->dbforge->add_key('cat_order');
$CI->dbforge->add_key('cat_display');
$CI->dbforge->create_table('categories');
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$data['cat_parent'] = $row['cat_parent'];
$data['cat_uri'] = $row['cat_uri'];
$data['cat_name'] = $row['cat_name'];
$data['cat_description'] = $row['cat_description'];
$display = 'no';
if ($row['cat_display'] == 1) {
$display = 'yes';
}
$data['cat_display'] = $display;
$data['cat_order'] = $row['cat_order'];
$this->db->insert('categories', $data);
}
}
$query->free_result();
}
$this->msg = 'Altered Categories Table.';
return $this->msg;
}