Skip to content

Commit 019e67a

Browse files
committed
Migrate legacy attachment discriminator class values to modern format, so that we can make the discriminator map unique and fix a deprecation with doctrine
1 parent f146d88 commit 019e67a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250222165240 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Migrate the old attachment class discriminator values from legacy Part-DB to the modern format, so that there is just one unified value';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
//Change the old discriminator values to the new ones
23+
$this->addSql('UPDATE attachments SET class_name = "Part" WHERE class_name = "PartDB\Part"');
24+
$this->addSql('UPDATE attachments SET class_name = "Device" WHERE class_name = "PartDB\Device"');
25+
}
26+
27+
public function down(Schema $schema): void
28+
{
29+
//No down required, as the new format can also be read by older Part-DB version
30+
}
31+
}

src/Entity/Attachments/Attachment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
#[DiscriminatorMap(typeProperty: '_type', mapping: self::API_DISCRIMINATOR_MAP)]
9797
abstract class Attachment extends AbstractNamedDBElement
9898
{
99-
private const ORM_DISCRIMINATOR_MAP = ['PartDB\Part' => PartAttachment::class, 'Part' => PartAttachment::class,
100-
'PartDB\Device' => ProjectAttachment::class, 'Device' => ProjectAttachment::class, 'AttachmentType' => AttachmentTypeAttachment::class,
99+
private const ORM_DISCRIMINATOR_MAP = ['Part' => PartAttachment::class, 'Device' => ProjectAttachment::class,
100+
'AttachmentType' => AttachmentTypeAttachment::class,
101101
'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class,
102102
'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class,
103103
'Storelocation' => StorageLocationAttachment::class, 'Supplier' => SupplierAttachment::class,

0 commit comments

Comments
 (0)