Skip to content

Commit 80a8fb3

Browse files
committed
fix: db structure fixes
1 parent 9e91b68 commit 80a8fb3

9 files changed

Lines changed: 6 additions & 143 deletions

database/migrations/2025_08_19_172834_create_pim_property_value_table.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ public function up(): void
1313
{
1414
Schema::create('pim_property_value', function (Blueprint $table) {
1515
$table->id();
16-
$table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade');
16+
$table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade')->onUpdate('cascade');
1717
$table->string('value');
1818
$table->smallInteger('sort')->default(0);
1919
$table->string('info_url')->nullable();
2020
$table->string('image')->nullable();
2121
$table->timestamps();
22-
$table->softDeletes();
2322
});
2423
}
2524

database/migrations/2025_08_19_174519_create_pim_product_type_has_property_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public function up(): void
1313
{
1414
Schema::create('pim_product_type_has_property', function (Blueprint $table) {
15-
$table->foreignId('product_type_id')->constrained('pim_product_types')->onDelete('cascade');
16-
$table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade');
15+
$table->foreignId('product_type_id')->constrained('pim_product_types')->onDelete('cascade')->onUpdate('cascade');
16+
$table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade')->onUpdate('cascade');
1717
$table->smallInteger('sort')->nullable();
1818
$table->timestamps();
1919
$table->primary(['product_type_id', 'property_id']);

database/migrations/2025_08_19_175623_create_catalogue_product_has_property_value_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public function up(): void
1313
{
1414
Schema::create('catalogue_product_has_property_value', function (Blueprint $table) {
15-
$table->foreignId('product_id')->constrained('catalogue_products')->onDelete('cascade');
16-
$table->foreignId('property_value_id')->constrained('pim_property_value')->onDelete('cascade');
15+
$table->foreignId('product_id')->constrained('catalogue_products')->onDelete('cascade')->onUpdate('cascade');
16+
$table->foreignId('property_value_id')->constrained('pim_property_value')->onDelete('cascade')->onUpdate('cascade');
1717
$table->timestamps();
1818
$table->unique(['product_id', 'property_value_id'], 'product_property_value_unique');
1919
});

database/migrations/2025_08_19_175841_add_indexes_to_property_tables.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Models/PropertyValue.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\BelongsTo;
99
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
10-
use Illuminate\Database\Eloquent\SoftDeletes;
1110
use Spatie\MediaLibrary\HasMedia;
1211
use Spatie\MediaLibrary\InteractsWithMedia;
1312
use Spatie\Translatable\HasTranslations;
1413

1514
class PropertyValue extends Model implements HasMedia
1615
{
17-
use HasFactory, HasTranslations, InteractsWithMedia, SoftDeletes;
16+
use HasFactory, HasTranslations, InteractsWithMedia;
1817

1918
protected $table = 'pim_property_value';
2019

@@ -55,16 +54,6 @@ public function registerMediaCollections(): void
5554
->useDisk('public');
5655
}
5756

58-
protected static function booted(): void
59-
{
60-
static::deleting(function (PropertyValue $value) {
61-
if ($value->isForceDeleting()) {
62-
// Delete product assignments
63-
$value->products()->detach();
64-
}
65-
});
66-
}
67-
6857
protected static function newFactory(): PropertyValueFactory
6958
{
7059
return PropertyValueFactory::new();

tests/Feature/PropertyCrudTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,6 @@
152152
]);
153153
});
154154

155-
it('cascades delete to property values', function () {
156-
$property = Property::factory()->create();
157-
$value = PropertyValue::factory()->create(['property_id' => $property->id]);
158-
159-
// First soft delete, then force delete to test cascade
160-
$property->delete();
161-
$property->forceDelete();
162-
163-
$this->assertDatabaseMissing('pim_property', [
164-
'id' => $property->id,
165-
]);
166-
167-
// Property value should also be force deleted due to cascade
168-
expect(PropertyValue::withTrashed()->find($value->id))->toBeNull();
169-
});
170-
171155
it('cascades delete to product type assignments', function () {
172156
$property = Property::factory()->create(['is_global' => false]);
173157
$productType = ProductType::factory()->create();

tests/Feature/PropertyIntegrationTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,3 @@
213213
'property_id' => $property->id,
214214
]);
215215
});
216-
217-
it('deleting property value removes product assignments', function () {
218-
$product = Product::factory()->create();
219-
$property = Property::factory()->create();
220-
$value = PropertyValue::factory()->create(['property_id' => $property->id]);
221-
222-
$product->propertyValues()->attach($value->id);
223-
224-
// Verify assignment exists
225-
$this->assertDatabaseHas('catalogue_product_has_property_value', [
226-
'product_id' => $product->id,
227-
'property_value_id' => $value->id,
228-
]);
229-
230-
// First soft delete, then force delete to test cascade
231-
$value->delete();
232-
$value->forceDelete();
233-
234-
// Verify assignment is removed
235-
$this->assertDatabaseMissing('catalogue_product_has_property_value', [
236-
'product_id' => $product->id,
237-
'property_value_id' => $value->id,
238-
]);
239-
});

tests/Feature/PropertyValueCrudTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,6 @@
5050
]);
5151
});
5252

53-
it('can soft delete a property value', function () {
54-
$value = PropertyValue::factory()->create();
55-
56-
$value->delete();
57-
58-
$this->assertSoftDeleted('pim_property_value', [
59-
'id' => $value->id,
60-
]);
61-
});
62-
63-
it('can restore a soft deleted property value', function () {
64-
$value = PropertyValue::factory()->create();
65-
66-
$value->delete();
67-
$value->restore();
68-
69-
$this->assertDatabaseHas('pim_property_value', [
70-
'id' => $value->id,
71-
'deleted_at' => null,
72-
]);
73-
});
74-
7553
it('maintains sort order when creating multiple values', function () {
7654
$property = Property::factory()->create();
7755

tests/Unit/PropertyValueTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,6 @@
8484
expect($sortedValues->last()->id)->toBe($value1->id);
8585
});
8686

87-
it('can soft delete property value', function () {
88-
$value = PropertyValue::factory()->create();
89-
$id = $value->id;
90-
91-
$value->delete();
92-
93-
expect(PropertyValue::find($id))->toBeNull();
94-
expect(PropertyValue::withTrashed()->find($id))->not->toBeNull();
95-
expect(PropertyValue::withTrashed()->find($id)->trashed())->toBeTrue();
96-
});
97-
98-
it('can restore soft deleted property value', function () {
99-
$value = PropertyValue::factory()->create();
100-
$value->delete();
101-
102-
$value->restore();
103-
104-
expect($value->trashed())->toBeFalse();
105-
expect(PropertyValue::find($value->id))->not->toBeNull();
106-
});
107-
10887
// Translation tests
10988
it('value attribute is translatable', function () {
11089
$value = PropertyValue::factory()->create([

0 commit comments

Comments
 (0)