30 lines
947 B
PHP
30 lines
947 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
final class Version20260128000100 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add identification number to receptions';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE reception ADD identification_number VARCHAR(20) DEFAULT NULL');
|
|
$this->addSql("UPDATE reception SET identification_number = 'N-BR-' || LPAD(id::text, 4, '0') WHERE identification_number IS NULL");
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_reception_identification_number ON reception (identification_number)');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('DROP INDEX UNIQ_reception_identification_number');
|
|
$this->addSql('ALTER TABLE reception DROP identification_number');
|
|
}
|
|
}
|