addSql('ALTER TABLE client_address ADD COLUMN is_broker BOOLEAN DEFAULT FALSE NOT NULL'); $this->addSql('ALTER TABLE client_address ADD COLUMN is_distributor BOOLEAN DEFAULT FALSE NOT NULL'); // Exclusivite miroir (filet de securite DBAL) : un type autonome interdit // tout autre drapeau. Livraison + Facturation restent cumulables entre eux. $this->addSql(<<<'SQL' ALTER TABLE client_address ADD CONSTRAINT chk_client_address_broker_exclusive CHECK (NOT (is_broker = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_distributor = TRUE))) SQL); $this->addSql(<<<'SQL' ALTER TABLE client_address ADD CONSTRAINT chk_client_address_distributor_exclusive CHECK (NOT (is_distributor = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_broker = TRUE))) SQL); $this->comment('client_address', 'is_broker', 'Adresse Courtier — type autonome exclusif de tout autre usage (chk_client_address_broker_exclusive). Faux par defaut.'); $this->comment('client_address', 'is_distributor', 'Adresse Distributeur — type autonome exclusif de tout autre usage (chk_client_address_distributor_exclusive). Faux par defaut.'); } public function down(Schema $schema): void { $this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_broker_exclusive'); $this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_distributor_exclusive'); $this->addSql('ALTER TABLE client_address DROP COLUMN is_distributor'); $this->addSql('ALTER TABLE client_address DROP COLUMN is_broker'); } /** * Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour * eviter tout echappement. */ private function comment(string $table, string $column, string $description): void { $this->addSql(sprintf( 'COMMENT ON COLUMN %s.%s IS $_$%s$_$', '"'.str_replace('"', '""', $table).'"', '"'.str_replace('"', '""', $column).'"', $description, )); } }