diff --git a/database/migrations/2025_11_26_230132_add_master_field_columns_to_item_fields_table.php b/database/migrations/2025_11_26_230132_add_master_field_columns_to_item_fields_table.php new file mode 100644 index 0000000..c4cdc31 --- /dev/null +++ b/database/migrations/2025_11_26_230132_add_master_field_columns_to_item_fields_table.php @@ -0,0 +1,102 @@ +Null === 'NO') { + Schema::table('item_fields', function (Blueprint $table) { + $table->unsignedBigInteger('section_id')->nullable()->comment('섹션 ID (NULL = 독립 필드)')->change(); + }); + } + + // 2. item_fields에 컬럼 추가 (이미 있으면 스킵) + if (! Schema::hasColumn('item_fields', 'category')) { + Schema::table('item_fields', function (Blueprint $table) { + $table->string('category', 100)->nullable()->after('properties')->comment('카테고리'); + $table->text('description')->nullable()->after('category')->comment('설명'); + $table->boolean('is_common')->default(false)->after('description')->comment('공통 필드 여부'); + }); + } + + // 3. item_master_fields 데이터를 item_fields로 이관 + DB::statement(' + INSERT INTO item_fields ( + tenant_id, group_id, section_id, field_name, field_type, + order_no, is_required, default_value, placeholder, + display_condition, validation_rules, options, properties, + category, description, is_common, + created_by, updated_by, deleted_by, + created_at, updated_at, deleted_at + ) + SELECT + m.tenant_id, + COALESCE(m.group_id, 1) as group_id, + NULL as section_id, + m.field_name, + m.field_type, + 0 as order_no, + 0 as is_required, + m.default_value, + NULL as placeholder, + NULL as display_condition, + m.validation_rules, + m.options, + m.properties, + m.category, + m.description, + m.is_common, + m.created_by, + m.updated_by, + m.deleted_by, + m.created_at, + m.updated_at, + m.deleted_at + FROM item_master_fields m + '); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // 이관된 데이터 삭제 (section_id = null인 레코드) + DB::table('item_fields') + ->whereNull('section_id') + ->delete(); + + // 컬럼 삭제 + Schema::table('item_fields', function (Blueprint $table) { + $table->dropColumn(['category', 'description', 'is_common']); + }); + + // section_id를 NOT NULL로 복원 + Schema::table('item_fields', function (Blueprint $table) { + $table->unsignedBigInteger('section_id')->nullable(false)->comment('섹션 ID')->change(); + }); + } +};