Files
Lesstime/migrations/Version20260624153709.php
T
Matthieu 5764d8f472
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m20s
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 1m26s
feat(directory) : type prestataire, validateurs front, autocomplete adresse BAN
- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*),
  ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3),
  DTO/service/drawer/fiche détail + onglet dédié dans le répertoire.
- Prospect : société uniquement (suppression du champ name, company requis) ;
  migration de backfill, conversion prospect→client et MCP adaptés.
- Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP).
- Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts,
  enregistrement bloqué tant qu'un champ est invalide.
- Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr)
  avec mode dégradé en saisie libre.
- Administration : retrait de l'onglet Clients.
2026-06-24 17:55:09 +02:00

90 lines
6.2 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260624153709 extends AbstractMigration
{
public function getDescription(): string
{
return 'Directory: prestataire entity + website on client/prospect/prestataire + prestataire ownership on contacts/addresses/reports + prospect company-only';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE prestataire (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT NULL, phone VARCHAR(50) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_by INT DEFAULT NULL, updated_by INT DEFAULT NULL, PRIMARY KEY (id))');
$this->addSql('CREATE INDEX IDX_60A26480DE12AB56 ON prestataire (created_by)');
$this->addSql('CREATE INDEX IDX_60A2648016FE72E1 ON prestataire (updated_by)');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A26480DE12AB56 FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A2648016FE72E1 FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER TABLE client ADD website VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE commercial_report ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT FK_886919D8BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_886919D8BE3DB2B7 ON commercial_report (prestataire_id)');
$this->addSql('ALTER TABLE directory_address ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT FK_6E5D9707BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_6E5D9707BE3DB2B7 ON directory_address (prestataire_id)');
$this->addSql('ALTER TABLE directory_contact ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT FK_2F711EBEBE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_2F711EBEBE3DB2B7 ON directory_contact (prestataire_id)');
// Prospect désormais société-only : on conserve la donnée existante en
// recopiant le nom dans la société quand celle-ci est vide, avant de
// rendre la colonne obligatoire et de supprimer la colonne name.
$this->addSql('ALTER TABLE prospect ADD website VARCHAR(255) DEFAULT NULL');
$this->addSql("UPDATE prospect SET company = name WHERE company IS NULL OR company = ''");
$this->addSql('ALTER TABLE prospect ALTER company SET NOT NULL');
$this->addSql('ALTER TABLE prospect DROP name');
// Ownership CHECK constraints: chaque ligne appartient à un client,
// un prospect OU un prestataire.
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT chk_contact_owner');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT chk_contact_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT chk_address_owner');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT chk_address_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT chk_report_owner');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT chk_report_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
}
public function down(Schema $schema): void
{
// Rétablit les contraintes d'ownership client/prospect (sans prestataire).
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT chk_contact_owner');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT chk_address_owner');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT chk_report_owner');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT FK_886919D8BE3DB2B7');
$this->addSql('DROP INDEX IDX_886919D8BE3DB2B7');
$this->addSql('ALTER TABLE commercial_report DROP prestataire_id');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT FK_6E5D9707BE3DB2B7');
$this->addSql('DROP INDEX IDX_6E5D9707BE3DB2B7');
$this->addSql('ALTER TABLE directory_address DROP prestataire_id');
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT FK_2F711EBEBE3DB2B7');
$this->addSql('DROP INDEX IDX_2F711EBEBE3DB2B7');
$this->addSql('ALTER TABLE directory_contact DROP prestataire_id');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT chk_contact_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT chk_address_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT chk_report_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE prestataire DROP CONSTRAINT FK_60A26480DE12AB56');
$this->addSql('ALTER TABLE prestataire DROP CONSTRAINT FK_60A2648016FE72E1');
$this->addSql('DROP TABLE prestataire');
$this->addSql('ALTER TABLE client DROP website');
// Restaure la colonne name (recopiée depuis company) puis l'oblige.
$this->addSql('ALTER TABLE prospect ADD name VARCHAR(255) DEFAULT NULL');
$this->addSql('UPDATE prospect SET name = company');
$this->addSql('ALTER TABLE prospect ALTER name SET NOT NULL');
$this->addSql('ALTER TABLE prospect DROP website');
$this->addSql('ALTER TABLE prospect ALTER company DROP NOT NULL');
}
}