<?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_offroad
 *
 * @author Fajar Dwi Rianto <fajar@earworks.co.id>
 * @since 1.0
 */

 class Migration_Add_offroad extends CI_Migration {

    public function up(){
        echo "Start Offroad Migration \n";
        $this->dbforge->add_field(array(
            'id' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ),
            'registerid' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true
            ),
            'vehicleid' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true
            ),
            'status' => array(
                'type' => 'SMALLINT',
                'constraint' => 1,
                'default' => 1,
                'comment' => '1 = pending, 2 = attend, 3 = cancel'
            ),
            'ordernumber' => array(
                'type' => 'INT',
                'constraint' => 3,
                'default' => 0,
                'comment' => 'order for view layout'
            ),
            '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_RegisterOffroad FOREIGN KEY (registerid) REFERENCES register(id) ON UPDATE CASCADE ON DELETE CASCADE',
            'CONSTRAINT FK_VehicleOffroad FOREIGN KEY (vehicleid) REFERENCES vehicle(id) ON UPDATE CASCADE ON DELETE CASCADE'
        ));
        $this->dbforge->add_key('id', true);
        if ($this->dbforge->create_table('offroad')){
            echo "Status : Success \n";
        } else {
            echo "Status : FAILED \n";
        }
    }

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