<?php

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

class CreateBuildsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('builds', function(Blueprint $table){
			$table->increments('id');
			$table->string('name');
			$table->double('price');
			$table->unsignedBigInteger('group_id')->nullable();
			$table->unsignedBigInteger('related_id');
			$table->enum('related_type', array('task', 'project'))->default('task');
			$table->unsignedBigInteger('stock_id')->nullable();
			$table->unsignedBigInteger('quantity');
			$table->enum('status', array('planning', 'in_progress', 'completed'))->default('planning');
			$table->unsignedBigInteger('created_by');
			$table->timestamps();

			$table->unique(array('related_id', 'related_type', 'stock_id', 'status'));

		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('builds');
	}

}
