Prepare modules
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
@ -12,18 +13,50 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->mediumIncrements('id');
|
||||
$table->smallIncrements('id');
|
||||
|
||||
// Clave del setting
|
||||
$table->string('key')->index();
|
||||
$table->text('value');
|
||||
|
||||
// Categoría (opcional pero recomendable)
|
||||
$table->string('category')->nullable()->index();
|
||||
|
||||
// Usuario (null para globales)
|
||||
$table->unsignedMediumInteger('user_id')->nullable()->index();
|
||||
|
||||
// Unique constraints
|
||||
$table->unique(['user_id', 'key']);
|
||||
// Valores segmentados por tipo para mejor rendimiento
|
||||
$table->string('value_string')->nullable();
|
||||
$table->integer('value_integer')->nullable();
|
||||
$table->boolean('value_boolean')->nullable();
|
||||
$table->float('value_float', 16, 8)->nullable();
|
||||
$table->text('value_text')->nullable();
|
||||
$table->binary('value_binary')->nullable();
|
||||
$table->string('mime_type', 50)->nullable();
|
||||
$table->string('file_name')->nullable();
|
||||
|
||||
// Auditoría
|
||||
$table->timestamps();
|
||||
$table->unsignedMediumInteger('updated_by')->nullable();
|
||||
|
||||
// Unique constraint para evitar duplicados
|
||||
$table->unique(['key', 'user_id', 'category']);
|
||||
|
||||
// Relaciones
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
|
||||
});
|
||||
|
||||
// Agregar columna virtual unificada
|
||||
DB::statement("ALTER TABLE settings ADD COLUMN value VARCHAR(255) GENERATED ALWAYS AS (
|
||||
CASE
|
||||
WHEN value_string IS NOT NULL THEN value_string
|
||||
WHEN value_integer IS NOT NULL THEN CAST(value_integer AS CHAR)
|
||||
WHEN value_boolean IS NOT NULL THEN IF(value_boolean, 'true', 'false')
|
||||
WHEN value_float IS NOT NULL THEN CAST(value_float AS CHAR)
|
||||
WHEN value_text IS NOT NULL THEN LEFT(value_text, 255)
|
||||
WHEN value_binary IS NOT NULL THEN '[binary_data]'
|
||||
ELSE NULL
|
||||
END
|
||||
) VIRTUAL");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?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('media_items', function (Blueprint $table) {
|
||||
$table->mediumIncrements('id');
|
||||
|
||||
// Relación polimórfica
|
||||
$table->unsignedMediumInteger('mediaable_id');
|
||||
$table->string('mediaable_type');
|
||||
|
||||
$table->unsignedTinyInteger('type')->index(); // Tipo de medio: 'image', 'video', 'file', 'youtube'
|
||||
$table->unsignedTinyInteger('sub_type')->index(); // Subtipo de medio: 'thumbnail', 'main', 'additional'
|
||||
|
||||
$table->string('url', 255)->nullable(); // URL del medio
|
||||
$table->string('path')->nullable(); // Ruta del archivo si está almacenado localmente
|
||||
|
||||
$table->string('title')->nullable()->index(); // Título del medio
|
||||
$table->mediumText('description')->nullable(); // Descripción del medio
|
||||
$table->unsignedTinyInteger('order')->nullable(); // Orden de presentación
|
||||
|
||||
// Authoría
|
||||
$table->timestamps();
|
||||
|
||||
// Índices
|
||||
$table->index(['mediaable_type', 'mediaable_id']);
|
||||
$table->index(['mediaable_type', 'mediaable_id', 'type']);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('images');
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user