<?php

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

class CreateAbServiceTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('ab_service', function(Blueprint $table)
		{
			$table->bigInteger('id')->default(0);
			$table->integer('site_id')->default(0);
			$table->bigInteger('date_orig')->nullable();
			$table->bigInteger('date_last')->nullable();
			$table->bigInteger('account_id')->default(0);
			$table->bigInteger('account_billing_id')->nullable();
			$table->bigInteger('product_id')->nullable();
			$table->boolean('active')->nullable();
			$table->boolean('suspend_billing')->nullable();
			$table->boolean('external_billing')->nullable();
			$table->float('price', 10, 0)->nullable();
			$table->integer('price_group')->default(0);
			$table->float('price_override', 10, 0)->nullable();
			$table->boolean('taxable')->nullable();
			$table->string('queue', 16)->nullable();
			$table->bigInteger('date_last_invoice')->nullable();
			$table->bigInteger('date_next_invoice')->nullable();
			$table->integer('recur_schedule')->nullable();
			$table->text('prod_attr')->nullable();
			$table->bigInteger('date_start')->nullable();
			$table->bigInteger('date_end')->nullable();
			$table->primary(['id','site_id','price_group']);
			$table->unique(['site_id','id','account_id'], 'UNIQUE');
			$table->index(['account_id','site_id'], 'fk_svc_acc_idx');
			$table->index(['site_id','price_group'], 'fk_svc_grp_idx');
		});
	}


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

}
