Skip to content

Commit 8727d83

Browse files
committed
Increase possible length of the vendor barcode column in part lots
This allows us to store full 2D barcodes content there
1 parent 70919d9 commit 8727d83

2 files changed

Lines changed: 75 additions & 3 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use App\Migration\AbstractMultiPlatformMigration;
8+
use Doctrine\DBAL\Schema\Schema;
9+
use Doctrine\Migrations\AbstractMigration;
10+
11+
final class Version20260307204859 extends AbstractMultiPlatformMigration
12+
{
13+
public function getDescription(): string
14+
{
15+
return 'Increase the length of the vendor_barcode field in part_lots to 1000 characters and update the index accordingly';
16+
}
17+
18+
public function mySQLUp(Schema $schema): void
19+
{
20+
$this->addSql('ALTER TABLE part_lots DROP INDEX part_lots_idx_barcode, ADD INDEX part_lots_idx_barcode (vendor_barcode(100))');
21+
$this->addSql('ALTER TABLE part_lots CHANGE vendor_barcode vendor_barcode LONGTEXT DEFAULT NULL');
22+
}
23+
24+
public function mySQLDown(Schema $schema): void
25+
{
26+
$this->addSql('ALTER TABLE part_lots DROP INDEX part_lots_idx_barcode, ADD INDEX part_lots_idx_barcode (vendor_barcode)');
27+
$this->addSql('ALTER TABLE part_lots CHANGE vendor_barcode vendor_barcode VARCHAR(255) DEFAULT NULL');
28+
}
29+
30+
public function sqLiteUp(Schema $schema): void
31+
{
32+
$this->addSql('CREATE TEMPORARY TABLE __temp__part_lots AS SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added, vendor_barcode, last_stocktake_at FROM part_lots');
33+
$this->addSql('DROP TABLE part_lots');
34+
$this->addSql('CREATE TABLE part_lots (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_store_location INTEGER DEFAULT NULL, id_part INTEGER NOT NULL, id_owner INTEGER DEFAULT NULL, description CLOB NOT NULL, comment CLOB NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown BOOLEAN NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, vendor_barcode CLOB DEFAULT NULL, last_stocktake_at DATETIME DEFAULT NULL, CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES storelocations (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES parts (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
35+
$this->addSql('INSERT INTO part_lots (id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added, vendor_barcode, last_stocktake_at) SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added, vendor_barcode, last_stocktake_at FROM __temp__part_lots');
36+
$this->addSql('DROP TABLE __temp__part_lots');
37+
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
38+
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
39+
$this->addSql('CREATE INDEX IDX_EBC8F9435D8F4B37 ON part_lots (id_store_location)');
40+
$this->addSql('CREATE INDEX IDX_EBC8F943C22F6CC4 ON part_lots (id_part)');
41+
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
42+
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
43+
}
44+
45+
public function sqLiteDown(Schema $schema): void
46+
{
47+
$this->addSql('CREATE TEMPORARY TABLE __temp__part_lots AS SELECT id, description, comment, expiration_date, instock_unknown, amount, needs_refill, vendor_barcode, last_stocktake_at, last_modified, datetime_added, id_store_location, id_part, id_owner FROM part_lots');
48+
$this->addSql('DROP TABLE part_lots');
49+
$this->addSql('CREATE TABLE part_lots (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, description CLOB NOT NULL, comment CLOB NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown BOOLEAN NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill BOOLEAN NOT NULL, vendor_barcode VARCHAR(255) DEFAULT NULL, last_stocktake_at DATETIME DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, id_store_location INTEGER DEFAULT NULL, id_part INTEGER NOT NULL, id_owner INTEGER DEFAULT NULL, CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES "storelocations" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
50+
$this->addSql('INSERT INTO part_lots (id, description, comment, expiration_date, instock_unknown, amount, needs_refill, vendor_barcode, last_stocktake_at, last_modified, datetime_added, id_store_location, id_part, id_owner) SELECT id, description, comment, expiration_date, instock_unknown, amount, needs_refill, vendor_barcode, last_stocktake_at, last_modified, datetime_added, id_store_location, id_part, id_owner FROM __temp__part_lots');
51+
$this->addSql('DROP TABLE __temp__part_lots');
52+
$this->addSql('CREATE INDEX IDX_EBC8F9435D8F4B37 ON part_lots (id_store_location)');
53+
$this->addSql('CREATE INDEX IDX_EBC8F943C22F6CC4 ON part_lots (id_part)');
54+
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
55+
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
56+
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
57+
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
58+
}
59+
60+
public function postgreSQLUp(Schema $schema): void
61+
{
62+
$this->addSql('DROP INDEX part_lots_idx_barcode');
63+
$this->addSql('ALTER TABLE part_lots ALTER vendor_barcode TYPE TEXT');
64+
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
65+
}
66+
67+
public function postgreSQLDown(Schema $schema): void
68+
{
69+
$this->addSql('DROP INDEX part_lots_idx_barcode');
70+
$this->addSql('ALTER TABLE part_lots ALTER vendor_barcode TYPE VARCHAR(255)');
71+
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
72+
}
73+
}

src/Entity/Parts/PartLot.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#[ORM\Table(name: 'part_lots')]
6767
#[ORM\Index(columns: ['instock_unknown', 'expiration_date', 'id_part'], name: 'part_lots_idx_instock_un_expiration_id_part')]
6868
#[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')]
69-
#[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')]
69+
#[ORM\Index(name: 'part_lots_idx_barcode', columns: ['vendor_barcode'], options: ['lengths' => [100]])]
7070
#[ValidPartLot]
7171
#[UniqueEntity(['user_barcode'], message: 'validator.part_lot.vendor_barcode_must_be_unique')]
7272
#[ApiResource(
@@ -166,9 +166,8 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
166166
/**
167167
* @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor)
168168
*/
169-
#[ORM\Column(name: "vendor_barcode", type: Types::STRING, nullable: true)]
169+
#[ORM\Column(name: "vendor_barcode", type: Types::TEXT, nullable: true)]
170170
#[Groups(['part_lot:read', 'part_lot:write'])]
171-
#[Length(max: 255)]
172171
protected ?string $user_barcode = null;
173172

174173
/**

0 commit comments

Comments
 (0)