Skip to content

Instantly share code, notes, and snippets.

@weotch
Forked from mattaebersold/histories.php
Last active May 26, 2016 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weotch/b516f2caa2ab64631a5c4d30d90a08b5 to your computer and use it in GitHub Desktop.
Save weotch/b516f2caa2ab64631a5c4d30d90a08b5 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateHistoriesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('histories', function($t){
$t->increments('id');
$t->integer('team_1_id')->unsigned();
$t->integer('team_1_score');
$t->integer('team_2_id')->unsigned();
$t->integer('team_2_score');
$t->date('date'); // No need for position because will be ordrered by date
$t->boolean('visible')->nullable();
$t->timestamps();
// Never forget your indexes, what you're ordering by is important
$t->index(['date', 'visible']);
$t->index(['visible', 'date']);
$t->foreign('team_1_id')
->references('id')->on('teams')
->onUpdate('cascade')
->onDelete('cascade');
$t->foreign('team_2_id')
->references('id')->on('teams')
->onUpdate('cascade')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('histories');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment