<?php

/*
 * Copyright (c) 2018 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 *  contact@earworks.co.id
 */
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Description of Migration_Add_profiles
 *
 * @author Fajar Dwi Rianto <fajar@earworks.co.id>
 * @since 1.0
 */
class Migration_Add_profiles extends CI_Migration {

    public function up() {
        echo "Start Profiles Table Migration \n";
        $this->dbforge->add_field(array(
            'profileid' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true
            ),
            'userid' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true
            ),
            'profilename' => array(
                'type' => 'VARCHAR',
                'constraint' => '255'
            ),
            'profileaddress' => array(
                'type' => 'TEXT',
                'null' => true,
            ),
            'profilemobile' => array(
                'type' => 'VARCHAR',
                'constraint' => '255',
                'null' => true
            ),
            'profilepath' => array(
                'type' => 'VARCHAR',
                'constraint' => '255',
                'null' => true
            ),
            'profilepathtitle' => array(
                'type' => 'VARCHAR',
                'constraint' => '255',
                'null' => true
            ),
            'profilepathalt' => array(
                'type' => 'VARCHAR',
                'constraint' => '255',
                'null' => true
            ),
            'created' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'modified' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'CONSTRAINT FK_UserProfile FOREIGN KEY (userid) REFERENCES users(userid) ON UPDATE CASCADE ON DELETE CASCADE'
        ));
        $this->dbforge->add_key('profileid', true);
        if ($this->dbforge->create_table('profiles')) {
            echo "Status : Success \n";
        } else {
            echo "Status : FAILED \n";
        }
    }

    public function down() {
        $this->dbforge->drop_table('profiles');
    }

}
