-
-
Save dmitrybubyakin/988cf697dcf7f0e881f969e03b460edb to your computer and use it in GitHub Desktop.
This file contains 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\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreateInterestsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
* @throws Exception | |
*/ | |
public function up() | |
{ | |
try { | |
Schema::create('interests', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('name', 256)->unique(); | |
$table->string('description', 512)->nullable(); | |
}); | |
Schema::create('interestables', function (Blueprint $table) { | |
$table->integer('interest_id')->unsigned(); | |
$table->morphs('interestable'); | |
$table->foreign('interest_id')->references('id')->on('interests') | |
->onDelete('cascade') | |
->onUpdate('cascade'); | |
$table->primary(['interest_id', 'interestable_id', 'interestable_type'], 'interestables_pk'); | |
}); | |
} catch (\Exception $e) { | |
$this->down(); | |
throw $e; | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('interestables'); | |
Schema::dropIfExists('interests'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment