<?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_vehicle
 * ALTER TABLE `vehicle` ADD `status` SMALLINT(1) NOT NULL DEFAULT '1' COMMENT '1= active, 2 = disable' AFTER `testtype`;
 * @author Fajar Dwi Rianto <fajar@earworks.co.id>
 * @since 1.0
 */

 class Migration_Add_vehicle extends CI_Migration {

    public function up(){
        echo "Start Vehicle Migration \n";
        $this->dbforge->add_field(array(
            'id' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => TRUE,
                'auto_increment' => TRUE,
            ),
            'name' => array(
                'type' => 'VARCHAR',
                'constraint' => 50,
            ),
            'testtype' => array(
                'type' => 'SMALLINT',
                'constraint' => 1,
                'default' => 1,
                'comment' => '1 = Offroad, 2 = Onroad, 3 = Test Drive'
            ),
            'status' => array(
                'type' => 'SMALLINT',
                'constraint' => 1,
                'default' => 1,
                'comment' => '1 = available, 2 = disable'
            ),
            '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
            )
        ));
        $this->dbforge->add_key('id', true);
        if ($this->dbforge->create_table('vehicle')){
            echo "Status : Success \n";
        } else {
            echo "Status : FAILED \n";
        }
    }

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