<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250324122956 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update webhook to manage multiple source & add fields entity and entity_id to manage sync';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE notification ADD entity VARCHAR(255) DEFAULT NULL, ADD entity_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE webhook DROP INDEX UNIQ_8A741756953C1C61, ADD INDEX IDX_8A741756953C1C61 (source_id)');
$this->addSql('ALTER TABLE webhook ADD object VARCHAR(255) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX source_object ON webhook (source_id, object)');
$this->addSql('UPDATE webhook SET object = "order"');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE notification DROP entity, DROP entity_id');
$this->addSql('ALTER TABLE `webhook` DROP INDEX IDX_8A741756953C1C61, ADD UNIQUE INDEX UNIQ_8A741756953C1C61 (source_id)');
$this->addSql('DROP INDEX source_object ON `webhook`');
$this->addSql('ALTER TABLE `webhook` DROP object');
}
}