migrations/Version20261006160000.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 Version20261006160000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add separately loaded per-customer PDF company name and validated logo storage.';
  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 IF NOT EXISTS customer_report_profiles_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  16.         $this->addSql('CREATE TABLE IF NOT EXISTS customer_report_profiles (id INT NOT NULL, customer_id INT NOT NULL, company_name VARCHAR(255) DEFAULT NULL, logo_data_uri TEXT DEFAULT NULL, PRIMARY KEY(id))');
  17.         $this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS UNIQ_REPORT_PROFILE_CUSTOMER ON customer_report_profiles (customer_id)');
  18.         $this->addSql(<<<'SQL'
  19. DO $$ BEGIN
  20.     IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_report_profile_customer' AND conrelid = 'customer_report_profiles'::regclass) THEN
  21.         ALTER TABLE customer_report_profiles ADD CONSTRAINT fk_report_profile_customer FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
  22.     END IF;
  23.     IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'chk_report_profile_logo' AND conrelid = 'customer_report_profiles'::regclass) THEN
  24.         ALTER TABLE customer_report_profiles ADD CONSTRAINT chk_report_profile_logo CHECK (logo_data_uri IS NULL OR (octet_length(logo_data_uri) <= 1398127 AND (logo_data_uri LIKE 'data:image/png;base64,%' OR logo_data_uri LIKE 'data:image/jpeg;base64,%')));
  25.     END IF;
  26. END $$;
  27. SQL
  28.         );
  29.     }
  30.     public function down(Schema $schema): void
  31.     {
  32.         $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on postgresql.');
  33.         $this->addSql('DROP TABLE IF EXISTS customer_report_profiles');
  34.         $this->addSql('DROP SEQUENCE IF EXISTS customer_report_profiles_id_seq');
  35.     }
  36. }