Add Prop and ModelPropValue models with relationships; create migration files for props, prop options, prop data types, and model prop values

This commit is contained in:
2026-06-22 12:07:46 -03:00
parent 93a2750d33
commit 5c81d6997a
12 changed files with 364 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
<?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('props_data_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('props_data_types');
}
};

View File

@@ -0,0 +1,36 @@
<?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('props', function (Blueprint $table) {
$table->id();
$table->string('propable_type');
$table->unsignedBigInteger('propable_id')->nullable();
$table->enum('scope', ['global', 'particular']);
$table->string('codigo')->unique();
$table->string('nombre');
$table->boolean('is_required')->default(false);
$table->foreignId('data_type_id')->constrained('props_data_types')->cascadeOnUpdate()->restrictOnDelete();
$table->timestamps();
$table->index(['propable_type', 'propable_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('props');
}
};

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('prop_options', function (Blueprint $table) {
$table->id();
$table->foreignId('prop_id')->constrained('props')->cascadeOnUpdate()->cascadeOnDelete();
$table->string('value');
$table->string('label');
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->unique(['prop_id', 'value']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('prop_options');
}
};

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('model_prop_values', function (Blueprint $table) {
$table->id();
$table->string('valuable_type');
$table->unsignedBigInteger('valuable_id');
$table->string('prop_codigo');
$table->text('value')->nullable();
$table->timestamps();
$table->foreign('prop_codigo')
->references('codigo')
->on('props')
->cascadeOnUpdate()
->cascadeOnDelete();
$table->unique(['valuable_type', 'valuable_id', 'prop_codigo']);
$table->index(['valuable_type', 'valuable_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('model_prop_values');
}
};