feat: refactor product attributes handling to use product_attribute table and update related models and requests

This commit is contained in:
2026-06-30 16:35:56 -03:00
parent 191a40fcb9
commit cb15905c46
15 changed files with 189 additions and 63 deletions

View File

@@ -36,6 +36,29 @@ return new class extends Migration
$table->unique(['product_id', 'attribute_id']);
});
// 4. Point variant values to the product-attribute pivot instead of the base attribute
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->dropForeign('productos_variantes_definiciones_attribute_id_foreign');
$table->dropUnique('prod_var_def_variant_attr_unique');
});
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->renameColumn('attribute_id', 'products_attribute_id');
});
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->foreign('products_attribute_id')
->references('id')
->on('products_attributes')
->cascadeOnUpdate()
->cascadeOnDelete();
$table->unique(
['producto_variante_id', 'products_attribute_id'],
'prod_var_values_variant_product_attr_unique'
);
});
}
/**
@@ -43,6 +66,25 @@ return new class extends Migration
*/
public function down(): void
{
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->dropForeign(['products_attribute_id']);
$table->dropUnique('prod_var_values_variant_product_attr_unique');
});
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->renameColumn('products_attribute_id', 'attribute_id');
});
Schema::table('productos_variantes_values', function (Blueprint $table) {
$table->foreign('attribute_id')
->references('id')
->on('attribute')
->cascadeOnUpdate()
->cascadeOnDelete();
$table->unique(['producto_variante_id', 'attribute_id'], 'prod_var_def_variant_attr_unique');
});
Schema::dropIfExists('products_attributes');
Schema::rename('productos_variantes_values', 'productos_variantes_definiciones');
Schema::rename('attribute', 'productos_attributes');