first commit

This commit is contained in:
2025-03-22 12:38:21 -06:00
commit 165d78cad1
28 changed files with 793 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_providers', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('name')->unique();
$table->string('slug')->unique()->index();
$table->string('api_endpoint');
$table->boolean('active')->default(true)->index();
// Auditoría
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_providers');
}
};

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_provider_settings', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('provider_id')->index();
$table->string('api_key');
$table->string('model')->nullable();
$table->float('temperature', 3, 2)->default(0.7);
$table->integer('max_tokens')->default(4096);
$table->float('frequency_penalty', 3, 2)->default(0.0);
$table->float('presence_penalty', 3, 2)->default(0.0);
// Auditoría
$table->timestamps();
// Relaciones
$table->foreign('provider_id')->references('id')->on('chatbot_providers')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_provider_settings');
}
};

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_client_settings', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedMediumInteger('user_id')->index();
$table->unsignedSmallInteger('provider_id')->index();
$table->json('preferences')->nullable()->comment('Ajustes personalizados específicos del cliente para el chatbot');
$table->decimal('monthly_budget', 10, 2)->default(0);
// Auditoría
$table->timestamps();
// Relaciones
$table->foreign('user_id')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
$table->foreign('provider_id')->references('id')->on('chatbot_providers')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_privacy_settings');
}
};

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_privacy_settings', function (Blueprint $table) {
$table->smallIncrements('id');
$table->boolean('store_conversations')->default(true);
$table->unsignedInteger('conversation_retention_days')->default(365);
$table->boolean('auto_anonymize')->default(true);
// Auditoría
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_privacy_settings');
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_resources', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('title');
$table->text('description')->nullable();
$table->string('resource_url');
$table->boolean('active')->default(true)->index();
// Auditoría
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_resources');
}
};

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_faqs', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('question')->unique();
$table->text('answer');
$table->unsignedInteger('priority')->default(0)->index();
$table->boolean('active')->default(true);
// Auditoría
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_faqs');
}
};

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_manual_training', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('input')->unique();
$table->text('expected_output');
$table->boolean('validated')->default(false)->index();
$table->unsignedMediumInteger('validated_by')->nullable();
$table->timestamp('validated_at')->nullable();
// Auditoría
$table->timestamps();
// Relaciones
$table->foreign('validated_by')->references('id')->on('users')->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_manual_training');
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_guests', function (Blueprint $table) {
$table->smallIncrements('id');
$table->uuid('uuid')->unique()->index();
$table->string('ip_address')->nullable();
$table->string('browser')->nullable();
$table->string('location')->nullable();
// Auditoría
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_guests');
}
};

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_conversations', function (Blueprint $table) {
$table->smallIncrements('id');
$table->uuid('uuid')->unique()->index();
// Relaciones polimórficas para participantes (usuarios, clientes, visitantes anónimos)
$table->unsignedMediumInteger('user_id')->nullable()->index();
$table->unsignedSmallInteger('provider_id')->index();
$table->enum('status', ['active', 'closed', 'archived'])->default('active')->index();
// Auditoría
$table->timestamps();
$table->softDeletes();
// Relaciones
$table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
$table->foreign('provider_id')->references('id')->on('chatbot_providers')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_conversations');
}
};

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_conversation_messages', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('conversation_id')->index();
$table->enum('sender', ['user', 'chatbot']);
$table->text('message');
$table->jsonb('metadata')->nullable()->comment('Información adicional del mensaje, como tokens usados, modelo usado, proveedor, etc.');
// Auditoría
$table->timestamps();
// Indices
$table->index(['conversation_id', 'sender']);
// Relaciones
$table->foreign('conversation_id')->references('id')->on('chatbot_conversations')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_conversation_messages');
}
};

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_usage_metrics', function (Blueprint $table) {
$table->smallIncrements('id');
$table->date('metric_date')->index();
$table->unsignedInteger('total_conversations')->default(0);
$table->unsignedInteger('total_messages')->default(0);
$table->unsignedInteger('unique_users')->default(0);
$table->unsignedInteger('guests')->default(0);
// Auditoría
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_usage_metrics');
}
};

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_user_feedback', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('conversation_id')->index();
$table->unsignedMediumInteger('user_id')->nullable()->index();
$table->integer('rating')->default(5)->index();
$table->text('feedback')->nullable();
// Auditoría
$table->timestamps();
// Indices
$table->index(['conversation_id', 'user_id']);
// Relaciones
$table->foreign('conversation_id')->references('id')->on('chatbot_conversations')->cascadeOnUpdate()->cascadeOnDelete();
$table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_user_feedback');
}
};

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_sensitive_data_logs', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('conversation_message_id')->index();
$table->string('detected_type')->index()->comment('Ej: RFC, Teléfono, Tarjeta de crédito');
$table->text('masked_data');
// Auditoría
$table->timestamps();
// Indices
$table->index(['conversation_message_id', 'detected_type'])->name('chatbot_sensitive_data_logs_message_detected_type_index');
// Relaciones
$table->foreign('conversation_message_id')->references('id')->on('chatbot_conversation_messages')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_sensitive_data_logs');
}
};

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_security_alerts', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('alert_type')->index();
$table->text('description');
$table->boolean('resolved')->default(false);
$table->timestamp('resolved_at')->nullable();
// Auditoría
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_security_alerts');
}
};

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chatbot_notifications_settings', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedMediumInteger('user_id')->index();
$table->boolean('email_notifications')->default(true);
$table->boolean('sms_notifications')->default(false);
$table->boolean('push_notifications')->default(true);
// Auditoría
$table->timestamps();
// Relaciones
$table->foreign('user_id')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chatbot_notifications_settings');
}
};