remove props

This commit is contained in:
2026-06-24 14:43:10 -03:00
parent 8e343ea9c3
commit 75129b7552
41 changed files with 10 additions and 1055 deletions

View File

@@ -1,34 +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('props', function (Blueprint $table) {
$table->id();
$table->string('propable_type');
$table->string('codigo')->unique();
$table->string('nombre');
$table->boolean('is_required')->default(false);
$table->string('data_type');
$table->timestamps();
$table->index('propable_type');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('props');
}
};

View File

@@ -1,33 +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('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

@@ -1,33 +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('model_prop_values', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('valuable_id');
$table->foreignId('prop_id')->constrained('props')->cascadeOnUpdate()->cascadeOnDelete();
$table->text('value')->nullable();
$table->timestamps();
$table->unique(['prop_id', 'valuable_id']);
$table->index('valuable_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('model_prop_values');
}
};

View File

@@ -1,106 +0,0 @@
<?php
use App\Domains\Prop\Support\PropDataType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('props')) {
return;
}
if (Schema::hasColumn('props', 'data_type_id')) {
Schema::table('props', function (Blueprint $table) {
$table->string('data_type')->nullable()->after('is_required');
});
if (Schema::hasTable('props_data_types')) {
$typeMap = DB::table('props_data_types')
->pluck('code', 'id')
->map(static fn (mixed $code): string => in_array($code, PropDataType::values(), true) ? (string) $code : PropDataType::String->value)
->all();
DB::table('props')
->select(['id', 'data_type_id'])
->orderBy('id')
->get()
->each(function (object $prop) use ($typeMap): void {
DB::table('props')
->where('id', $prop->id)
->update([
'data_type' => $typeMap[$prop->data_type_id] ?? PropDataType::String->value,
]);
});
} else {
DB::table('props')->update([
'data_type' => PropDataType::String->value,
]);
}
Schema::table('props', function (Blueprint $table) {
$table->dropForeign(['data_type_id']);
$table->dropColumn('data_type_id');
});
Schema::table('props', function (Blueprint $table) {
$table->string('data_type')->nullable(false)->change();
});
}
if (Schema::hasTable('props_data_types')) {
Schema::drop('props_data_types');
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (! Schema::hasTable('props_data_types')) {
Schema::create('props_data_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code')->unique();
$table->timestamps();
});
DB::table('props_data_types')->insert([
[
'id' => 1,
'name' => 'String',
'code' => PropDataType::String->value,
'created_at' => now(),
'updated_at' => now(),
],
]);
}
if (Schema::hasTable('props') && Schema::hasColumn('props', 'data_type') && ! Schema::hasColumn('props', 'data_type_id')) {
Schema::table('props', function (Blueprint $table) {
$table->foreignId('data_type_id')->nullable()->after('is_required')->constrained('props_data_types')->cascadeOnUpdate()->restrictOnDelete();
});
$stringTypeId = DB::table('props_data_types')
->where('code', PropDataType::String->value)
->value('id');
DB::table('props')->update([
'data_type_id' => $stringTypeId,
]);
Schema::table('props', function (Blueprint $table) {
$table->foreignId('data_type_id')->nullable(false)->change();
$table->dropColumn('data_type');
});
}
}
};