<?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_register
 *
 * @author Fajar Dwi Rianto <fajar@earworks.co.id>
 * @since 1.0
 */
class Migration_Add_register extends CI_Migration {

    public function up() {
        echo "Start Register Migration \n";
        $this->dbforge->add_field(array(
            'id' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ),
            'cardid' => array(
                'type' => 'INT',
                'constraint' => 11,
                'default' => 1,
                'unsigned' => true
            ),
            'company' => array(
                'type' => 'VARCHAR',
                'constraint' => 255
            ),
            'dealer' => array(
                'type' => 'VARCHAR',
                'constraint' => 255,
                'null' => true
            ),
            'name' => array(
                'type' => 'VARCHAR',
                'constraint' => 255
            ),
            'type' => array(
                'type' => 'SMALLINT',
                'constraint' => 1,
                'default' => 1,
                'comment' => '1 = Coorporate, 2 = Media, 3 = Internal'
            ),
            'testonroad' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'null' => true,
            ),
            'testoffroad' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'null' => true,
            ),
            'testdrive' => array(
                'type' => 'VARCHAR',
                'constraint' => 100,
                'null' => true
            ),
            'created' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'modified' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'createdby' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'modifiedby' => array(
                'type' => 'INT',
                'constraint' => 11,
                'null' => true
            ),
            'CONSTRAINT FK_CardRegister FOREIGN KEY (cardid) REFERENCES card(id) ON UPDATE CASCADE ON DELETE CASCADE',
            'CONSTRAINT FK_OnroadRegister FOREIGN KEY (testonroad) REFERENCES vehicle(id) ON UPDATE CASCADE ON DELETE CASCADE',
            'CONSTRAINT FK_OffroadRegister FOREIGN KEY (testoffroad) REFERENCES vehicle(id) ON UPDATE CASCADE ON DELETE CASCADE'
        ));
        $this->dbforge->add_key('id', true);
        if ($this->dbforge->create_table('register')) {
            echo "Status : Success \n";
        } else {
            echo "Status : FAILED \n";
        }
    }

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

}
