| @@ 7-39 (lines=33) @@ | ||
| 4 | use Illuminate\Database\Schema\Blueprint; | |
| 5 | use Illuminate\Database\Migrations\Migration; | |
| 6 | ||
| 7 | class CreateSnippetsTable extends Migration | |
| 8 | { | |
| 9 | /** | |
| 10 | * Run the migrations. | |
| 11 | * | |
| 12 | * @return void | |
| 13 | */ | |
| 14 | public function up() | |
| 15 |     { | |
| 16 |         Schema::create('snippets', function (Blueprint $table) { | |
| 17 |             $table->increments('id'); | |
| 18 |             $table->unsignedInteger('user_id'); | |
| 19 |             $table->unsignedInteger('forked_id')->nullable(); | |
| 20 |             $table->string('title'); | |
| 21 |             $table->text('body'); | |
| 22 | $table->timestamps(); | |
| 23 | ||
| 24 |             $table->foreign('user_id') | |
| 25 |                   ->references('id')->on('users') | |
| 26 |                   ->onDelete('cascade'); | |
| 27 | }); | |
| 28 | } | |
| 29 | ||
| 30 | /** | |
| 31 | * Reverse the migrations. | |
| 32 | * | |
| 33 | * @return void | |
| 34 | */ | |
| 35 | public function down() | |
| 36 |     { | |
| 37 |         Schema::dropIfExists('snippets'); | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| @@ 7-41 (lines=35) @@ | ||
| 4 | use Illuminate\Database\Schema\Blueprint; | |
| 5 | use Illuminate\Database\Migrations\Migration; | |
| 6 | ||
| 7 | class CreateSnippetsVotes extends Migration | |
| 8 | { | |
| 9 | /** | |
| 10 | * Run the migrations. | |
| 11 | * | |
| 12 | * @return void | |
| 13 | */ | |
| 14 | public function up() | |
| 15 |     { | |
| 16 |         Schema::create('snippets_votes', function (Blueprint $table) { | |
| 17 |             $table->increments('id'); | |
| 18 |             $table->unsignedInteger('user_id'); | |
| 19 |             $table->unsignedInteger('snippet_id'); | |
| 20 | $table->timestamps(); | |
| 21 | ||
| 22 |             $table->foreign('user_id') | |
| 23 |                   ->references('id')->on('users') | |
| 24 |                   ->onDelete('cascade'); | |
| 25 | ||
| 26 |             $table->foreign('snippet_id') | |
| 27 |                   ->references('id')->on('snippets') | |
| 28 |                   ->onDelete('cascade'); | |
| 29 | }); | |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * Reverse the migrations. | |
| 34 | * | |
| 35 | * @return void | |
| 36 | */ | |
| 37 | public function down() | |
| 38 |     { | |
| 39 |         Schema::dropIfExists('snippets_votes'); | |
| 40 | } | |
| 41 | } | |
| 42 | ||