| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- /*
- * Миграция: создаёт таблицу dict_values — значения справочников.
- * Создана: 2026-05-06
- * section_id → dict_sections (onDelete cascade: удаление раздела удаляет все его значения)
- * parent_id → dict_values (самоссылающийся FK; NULL = корневое, не NULL = дочернее значение)
- * Нет timestamps — значения справочников не требуют отслеживания времени
- */
- return new class extends Migration
- {
- public function up(): void
- {
- Schema::create('dict_values', function (Blueprint $table) {
- $table->unsignedBigInteger('id')->autoIncrement();
- $table->unsignedBigInteger('section_id');
- $table->unsignedBigInteger('parent_id')->nullable();
- $table->string('value', 255);
- $table->smallInteger('sort_order')->default(0);
- $table->index('section_id', 'idx_section');
- $table->index('parent_id', 'idx_parent');
- $table->foreign('section_id')->references('id')->on('dict_sections')->onDelete('cascade');
- $table->foreign('parent_id')->references('id')->on('dict_values')->onDelete('cascade');
- });
- }
- /**
- * Reverse the migrations.
- */
- public function down(): void
- {
- Schema::dropIfExists('dict_values');
- }
- };
|