-
-
Save weotch/b516f2caa2ab64631a5c4d30d90a08b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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