Просмотр файла database/migrations/20180420180005_create_articles_table.php

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