Просмотр файла database/migrations/2018_04_20_180005_create_articles_table.php

Размер файла: 1.36Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. use Illuminate\Database\Migrations\Migration;
  6. use Illuminate\Database\Schema\Blueprint;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Schema;
  9.  
  10. final class CreateArticlesTable extends Migration
  11. {
  12. /**
  13. * Migrate Up.
  14. */
  15. public function up(): void
  16. {
  17. if (! Schema::hasTable('articles')) {
  18. Schema::create('articles', function (Blueprint $table) {
  19. $table->increments('id');
  20. $table->integer('category_id');
  21. $table->integer('user_id');
  22. $table->string('title', 50);
  23. $table->text('text');
  24. $table->string('tags', 100);
  25. $table->integer('rating')->default(0);
  26. $table->integer('visits')->default(0);
  27. $table->integer('count_comments')->default(0);
  28. $table->integer('created_at');
  29.  
  30. $table->index('category_id');
  31. $table->index('user_id');
  32. $table->index('created_at');
  33. });
  34.  
  35. if (config('database.default') === 'mysql') {
  36. DB::statement('CREATE FULLTEXT INDEX articles_title_text_fulltext ON articles(title, text);');
  37. }
  38. }
  39. }
  40.  
  41. /**
  42. * Migrate Down.
  43. */
  44. public function down(): void
  45. {
  46. Schema::dropIfExists('articles');
  47. }
  48. }