<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterStockTableAddQuantityOnOrder extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::table('parts', function(Blueprint $table){
            $table->integer('quantity_on_order')->default(0);
        });

        Schema::table('parts', function(Blueprint $table){
            DB::statement("UPDATE `parts` SET `quantity_on_order` = `quantity` WHERE `on_order` = 1");
        });

        Schema::table('parts', function(Blueprint $table){
            $table->dropColumn('on_order');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('parts', function(Blueprint $table){
            $table->boolean('on_order')->default(false);
        });

        Schema::table('parts', function(Blueprint $table){
            DB::statement("UPDATE `parts` SET `quantity_on_order` = true WHERE `quantity_on_order` > 0");
        });

        Schema::table('parts', function(Blueprint $table){
            $table->dropColumn('quantity_on_order');
        });
        
    }


}
