<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Drop source-period uniqueness so older firmware counters do not block ingest.
*/
final class Version20260405120000 extends AbstractMigration
{
public function getDescription() : string
{
return 'Drop source period/item unique indexes while keeping replay metadata columns.';
}
public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP INDEX IF EXISTS UNIQ_M_DEV_PERIOD');
$this->addSql('DROP INDEX IF EXISTS UNIQ_DS_DEV_PERIOD_ITEM');
}
public function down(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE UNIQUE INDEX UNIQ_DS_DEV_PERIOD_ITEM ON data_samples (device_id, source_period, source_item) WHERE source_period IS NOT NULL AND source_item IS NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_M_DEV_PERIOD ON measurements (device_id, source_period) WHERE source_period IS NOT NULL');
}
}