<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261006160000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add separately loaded per-customer PDF company name and validated logo storage.';
}
public function up(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on postgresql.');
$this->addSql('CREATE SEQUENCE IF NOT EXISTS customer_report_profiles_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$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))');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS UNIQ_REPORT_PROFILE_CUSTOMER ON customer_report_profiles (customer_id)');
$this->addSql(<<<'SQL'
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'fk_report_profile_customer' AND conrelid = 'customer_report_profiles'::regclass) THEN
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;
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'chk_report_profile_logo' AND conrelid = 'customer_report_profiles'::regclass) THEN
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,%')));
END IF;
END $$;
SQL
);
}
public function down(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on postgresql.');
$this->addSql('DROP TABLE IF EXISTS customer_report_profiles');
$this->addSql('DROP SEQUENCE IF EXISTS customer_report_profiles_id_seq');
}
}