2026_05_06_151148_create_dict_values_table.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. /*
  6. * Миграция: создаёт таблицу dict_values — значения справочников.
  7. * Создана: 2026-05-06
  8. * section_id → dict_sections (onDelete cascade: удаление раздела удаляет все его значения)
  9. * parent_id → dict_values (самоссылающийся FK; NULL = корневое, не NULL = дочернее значение)
  10. * Нет timestamps — значения справочников не требуют отслеживания времени
  11. */
  12. return new class extends Migration
  13. {
  14. public function up(): void
  15. {
  16. Schema::create('dict_values', function (Blueprint $table) {
  17. $table->unsignedBigInteger('id')->autoIncrement();
  18. $table->unsignedBigInteger('section_id');
  19. $table->unsignedBigInteger('parent_id')->nullable();
  20. $table->string('value', 255);
  21. $table->smallInteger('sort_order')->default(0);
  22. $table->index('section_id', 'idx_section');
  23. $table->index('parent_id', 'idx_parent');
  24. $table->foreign('section_id')->references('id')->on('dict_sections')->onDelete('cascade');
  25. $table->foreign('parent_id')->references('id')->on('dict_values')->onDelete('cascade');
  26. });
  27. }
  28. /**
  29. * Reverse the migrations.
  30. */
  31. public function down(): void
  32. {
  33. Schema::dropIfExists('dict_values');
  34. }
  35. };