diff --git a/migrations/Version20260402202809.php b/migrations/Version20260402202809.php new file mode 100644 index 0000000..2082fd7 --- /dev/null +++ b/migrations/Version20260402202809.php @@ -0,0 +1,53 @@ +addSql('CREATE TABLE facture (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, split_index SMALLINT DEFAULT 0 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, order_number_id INT NOT NULL, advert_id INT DEFAULT NULL, PRIMARY KEY (id))'); + $this->addSql('CREATE INDEX IDX_FE8664108C26A5E8 ON facture (order_number_id)'); + $this->addSql('CREATE INDEX IDX_FE866410D07ECCB6 ON facture (advert_id)'); + $this->addSql('ALTER TABLE facture ADD CONSTRAINT FK_FE8664108C26A5E8 FOREIGN KEY (order_number_id) REFERENCES order_number (id) NOT DEFERRABLE'); + $this->addSql('ALTER TABLE facture ADD CONSTRAINT FK_FE866410D07ECCB6 FOREIGN KEY (advert_id) REFERENCES advert (id) NOT DEFERRABLE'); + $this->addSql('ALTER TABLE "order" DROP CONSTRAINT fk_f5299398d07eccb6'); + $this->addSql('ALTER TABLE "order" DROP CONSTRAINT fk_f52993988c26a5e8'); + $this->addSql('DROP TABLE "order"'); + $this->addSql('DROP INDEX uniq_54f1f40b8c26a5e8'); + $this->addSql('CREATE INDEX IDX_54F1F40B8C26A5E8 ON advert (order_number_id)'); + $this->addSql('DROP INDEX uniq_8b27c52b8c26a5e8'); + $this->addSql('CREATE INDEX IDX_8B27C52B8C26A5E8 ON devis (order_number_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TABLE "order" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, split_index SMALLINT DEFAULT 0 NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, order_number_id INT NOT NULL, advert_id INT DEFAULT NULL, PRIMARY KEY (id))'); + $this->addSql('CREATE INDEX idx_f5299398d07eccb6 ON "order" (advert_id)'); + $this->addSql('CREATE UNIQUE INDEX uniq_f52993988c26a5e8 ON "order" (order_number_id)'); + $this->addSql('ALTER TABLE "order" ADD CONSTRAINT fk_f5299398d07eccb6 FOREIGN KEY (advert_id) REFERENCES advert (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE "order" ADD CONSTRAINT fk_f52993988c26a5e8 FOREIGN KEY (order_number_id) REFERENCES order_number (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE facture DROP CONSTRAINT FK_FE8664108C26A5E8'); + $this->addSql('ALTER TABLE facture DROP CONSTRAINT FK_FE866410D07ECCB6'); + $this->addSql('DROP TABLE facture'); + $this->addSql('DROP INDEX IDX_54F1F40B8C26A5E8'); + $this->addSql('CREATE UNIQUE INDEX uniq_54f1f40b8c26a5e8 ON advert (order_number_id)'); + $this->addSql('DROP INDEX IDX_8B27C52B8C26A5E8'); + $this->addSql('CREATE UNIQUE INDEX uniq_8b27c52b8c26a5e8 ON devis (order_number_id)'); + } +} diff --git a/src/Entity/Advert.php b/src/Entity/Advert.php index 201a107..92db721 100644 --- a/src/Entity/Advert.php +++ b/src/Entity/Advert.php @@ -15,7 +15,7 @@ class Advert #[ORM\Column] private ?int $id = null; - #[ORM\OneToOne(targetEntity: OrderNumber::class)] + #[ORM\ManyToOne(targetEntity: OrderNumber::class)] #[ORM\JoinColumn(nullable: false)] private OrderNumber $orderNumber; @@ -26,15 +26,15 @@ class Advert #[ORM\Column] private \DateTimeImmutable $createdAt; - /** @var Collection */ - #[ORM\OneToMany(targetEntity: Order::class, mappedBy: 'advert')] - private Collection $orders; + /** @var Collection */ + #[ORM\OneToMany(targetEntity: Facture::class, mappedBy: 'advert')] + private Collection $factures; public function __construct(OrderNumber $orderNumber) { $this->orderNumber = $orderNumber; $this->createdAt = new \DateTimeImmutable(); - $this->orders = new ArrayCollection(); + $this->factures = new ArrayCollection(); } public function getId(): ?int @@ -62,9 +62,9 @@ class Advert return $this->createdAt; } - /** @return Collection */ - public function getOrders(): Collection + /** @return Collection */ + public function getFactures(): Collection { - return $this->orders; + return $this->factures; } } diff --git a/src/Entity/Devis.php b/src/Entity/Devis.php index e53b003..bc94960 100644 --- a/src/Entity/Devis.php +++ b/src/Entity/Devis.php @@ -15,7 +15,7 @@ class Devis #[ORM\Column] private ?int $id = null; - #[ORM\OneToOne(targetEntity: OrderNumber::class)] + #[ORM\ManyToOne(targetEntity: OrderNumber::class)] #[ORM\JoinColumn(nullable: false)] private OrderNumber $orderNumber; diff --git a/src/Entity/Order.php b/src/Entity/Facture.php similarity index 86% rename from src/Entity/Order.php rename to src/Entity/Facture.php index 96d0ef5..0ed4a56 100644 --- a/src/Entity/Order.php +++ b/src/Entity/Facture.php @@ -2,23 +2,22 @@ namespace App\Entity; -use App\Repository\OrderRepository; +use App\Repository\FactureRepository; use Doctrine\ORM\Mapping as ORM; -#[ORM\Entity(repositoryClass: OrderRepository::class)] -#[ORM\Table(name: '`order`')] -class Order +#[ORM\Entity(repositoryClass: FactureRepository::class)] +class Facture { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; - #[ORM\OneToOne(targetEntity: OrderNumber::class)] + #[ORM\ManyToOne(targetEntity: OrderNumber::class)] #[ORM\JoinColumn(nullable: false)] private OrderNumber $orderNumber; - #[ORM\ManyToOne(targetEntity: Advert::class, inversedBy: 'orders')] + #[ORM\ManyToOne(targetEntity: Advert::class, inversedBy: 'factures')] #[ORM\JoinColumn(nullable: true)] private ?Advert $advert = null; diff --git a/src/Repository/OrderRepository.php b/src/Repository/FactureRepository.php similarity index 56% rename from src/Repository/OrderRepository.php rename to src/Repository/FactureRepository.php index 22af896..abcd24f 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/FactureRepository.php @@ -2,17 +2,17 @@ namespace App\Repository; -use App\Entity\Order; +use App\Entity\Facture; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** - * @extends ServiceEntityRepository + * @extends ServiceEntityRepository */ -class OrderRepository extends ServiceEntityRepository +class FactureRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, Order::class); + parent::__construct($registry, Facture::class); } }