migrations/Version20260909120000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20260909120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add one-shot per-user temperature notifications without changing strength notifications.';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on postgresql.');
  15.         $this->addSql('CREATE SEQUENCE temperature_notifications_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  16.         $this->addSql("CREATE TABLE temperature_notifications (id INT NOT NULL, user_id INT NOT NULL, channel_setting_id INT NOT NULL, temperature_trigger DOUBLE PRECISION NOT NULL, direction VARCHAR(16) DEFAULT 'above' NOT NULL, triggered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT CHK_TEMPERATURE_NOTIFICATION_DIRECTION CHECK (direction IN ('above', 'below')), CONSTRAINT CHK_TEMPERATURE_NOTIFICATION_RANGE CHECK (temperature_trigger >= -273.15 AND temperature_trigger <= 1416833))");
  17.         $this->addSql('COMMENT ON COLUMN temperature_notifications.temperature_trigger IS \'Temperature in degrees Celsius that triggers this notification.\'');
  18.         $this->addSql('COMMENT ON COLUMN temperature_notifications.direction IS \'Alarm direction: above or below.\'');
  19.         $this->addSql('COMMENT ON COLUMN temperature_notifications.triggered_at IS \'When this notification was triggered.\'');
  20.         $this->addSql('COMMENT ON COLUMN temperature_notifications.created_at IS \'Date of the entity creation. Should be fixed.\'');
  21.         $this->addSql('COMMENT ON COLUMN temperature_notifications.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  22.         $this->addSql('CREATE INDEX IDX_TEMPERATURE_NOTIFICATION_USER ON temperature_notifications (user_id)');
  23.         $this->addSql('CREATE INDEX IDX_TEMPERATURE_NOTIFICATION_CHANNEL ON temperature_notifications (channel_setting_id)');
  24.         $this->addSql('CREATE INDEX IDX_TEMPERATURE_NOTIFICATION_PENDING ON temperature_notifications (channel_setting_id, id) WHERE (triggered_at IS NULL)');
  25.         $this->addSql('CREATE UNIQUE INDEX UNIQ_TEMPERATURE_NOTIFICATION_PENDING ON temperature_notifications (user_id, channel_setting_id, temperature_trigger, direction, email) WHERE (triggered_at IS NULL)');
  26.         $this->addSql('ALTER TABLE temperature_notifications ADD CONSTRAINT FK_TEMPERATURE_NOTIFICATION_USER FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  27.         $this->addSql('ALTER TABLE temperature_notifications ADD CONSTRAINT FK_TEMPERATURE_NOTIFICATION_CHANNEL FOREIGN KEY (channel_setting_id) REFERENCES channel_settings (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on postgresql.');
  32.         $this->addSql('DROP TABLE temperature_notifications');
  33.         $this->addSql('DROP SEQUENCE temperature_notifications_id_seq CASCADE');
  34.     }
  35. }