<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261025120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Rename table restaurante to restaurant and role ROLE_RESTAURANTE to ROLE_RESTAURANT';
}
public function up(Schema $schema): void
{
// MySQL repoints the foreign keys of menu and image to the renamed table by itself.
$this->addSql('ALTER TABLE restaurante DROP FOREIGN KEY FK_5957C2756B3CA4B');
$this->addSql('RENAME TABLE restaurante TO restaurant');
$this->addSql('ALTER TABLE restaurant RENAME INDEX IDX_5957C2756B3CA4B TO IDX_EB95123F6B3CA4B');
$this->addSql('ALTER TABLE restaurant ADD CONSTRAINT FK_EB95123F6B3CA4B FOREIGN KEY (id_user) REFERENCES `user` (id)');
$this->addSql("UPDATE `user` SET roles = CAST(REPLACE(CAST(roles AS CHAR), 'ROLE_RESTAURANTE', 'ROLE_RESTAURANT') AS JSON)");
}
public function down(Schema $schema): void
{
$this->addSql("UPDATE `user` SET roles = CAST(REPLACE(CAST(roles AS CHAR), 'ROLE_RESTAURANT', 'ROLE_RESTAURANTE') AS JSON)");
$this->addSql('ALTER TABLE restaurant DROP FOREIGN KEY FK_EB95123F6B3CA4B');
$this->addSql('RENAME TABLE restaurant TO restaurante');
$this->addSql('ALTER TABLE restaurante RENAME INDEX IDX_EB95123F6B3CA4B TO IDX_5957C2756B3CA4B');
$this->addSql('ALTER TABLE restaurante ADD CONSTRAINT FK_5957C2756B3CA4B FOREIGN KEY (id_user) REFERENCES `user` (id)');
}
}