From 36b87e98173cc8ab49c550f83c8b05bef919ddc4 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Sun, 28 Jun 2026 17:04:23 +0330 Subject: [PATCH] fix(db): declare onDelete on required FKs that had none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eight required (nullable:false) FKs had no referential action. Set per the codebase's existing pattern: CASCADE for owned relations (doctor_insurances, doctor_secretaries), RESTRICT for owner/reference FKs (Doctor/Clinic.user_id, invited_by_id, subscription plan/period). Only the two CASCADE FKs need DDL — RESTRICT is the MySQL default. --- migrations/Version20260628133044.php | 35 +++++++++++++++++++ src/Clinic/Entity/Clinic.php | 2 +- .../Entity/ClinicDoctorInvitation.php | 2 +- src/Doctor/Entity/Doctor.php | 2 +- src/Insurance/Entity/DoctorInsurance.php | 2 +- src/Secretary/Entity/DoctorSecretary.php | 2 +- .../Entity/ClinicSubscription.php | 4 +-- .../Entity/SubscriptionPeriod.php | 2 +- 8 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 migrations/Version20260628133044.php diff --git a/migrations/Version20260628133044.php b/migrations/Version20260628133044.php new file mode 100644 index 00000000..597a4498 --- /dev/null +++ b/migrations/Version20260628133044.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE doctor_insurances DROP FOREIGN KEY `FK_5317E58ED1E63CD1`'); + $this->addSql('ALTER TABLE doctor_insurances ADD CONSTRAINT FK_5317E58ED1E63CD1 FOREIGN KEY (insurance_id) REFERENCES insurances (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE doctor_secretaries DROP FOREIGN KEY `FK_8DF480E9A2A63DB2`'); + $this->addSql('ALTER TABLE doctor_secretaries ADD CONSTRAINT FK_8DF480E9A2A63DB2 FOREIGN KEY (secretary_id) REFERENCES users (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE doctor_insurances DROP FOREIGN KEY FK_5317E58ED1E63CD1'); + $this->addSql('ALTER TABLE doctor_insurances ADD CONSTRAINT `FK_5317E58ED1E63CD1` FOREIGN KEY (insurance_id) REFERENCES insurances (id)'); + $this->addSql('ALTER TABLE doctor_secretaries DROP FOREIGN KEY FK_8DF480E9A2A63DB2'); + $this->addSql('ALTER TABLE doctor_secretaries ADD CONSTRAINT `FK_8DF480E9A2A63DB2` FOREIGN KEY (secretary_id) REFERENCES users (id)'); + } +} diff --git a/src/Clinic/Entity/Clinic.php b/src/Clinic/Entity/Clinic.php index 3e57b73f..37943d1b 100644 --- a/src/Clinic/Entity/Clinic.php +++ b/src/Clinic/Entity/Clinic.php @@ -29,7 +29,7 @@ class Clinic private string $uuid; #[ORM\ManyToOne(targetEntity: User::class)] - #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')] private User $user; #[ORM\Column(type: 'string', length: 255, nullable: true)] diff --git a/src/ClinicInvitation/Entity/ClinicDoctorInvitation.php b/src/ClinicInvitation/Entity/ClinicDoctorInvitation.php index cc9f2a19..16845f53 100644 --- a/src/ClinicInvitation/Entity/ClinicDoctorInvitation.php +++ b/src/ClinicInvitation/Entity/ClinicDoctorInvitation.php @@ -34,7 +34,7 @@ class ClinicDoctorInvitation private Clinic $clinic; #[ORM\ManyToOne(targetEntity: User::class)] - #[ORM\JoinColumn(name: 'invited_by_id', referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(name: 'invited_by_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')] private User $invitedBy; #[ORM\ManyToOne(targetEntity: Doctor::class)] diff --git a/src/Doctor/Entity/Doctor.php b/src/Doctor/Entity/Doctor.php index 3472d029..125f4009 100644 --- a/src/Doctor/Entity/Doctor.php +++ b/src/Doctor/Entity/Doctor.php @@ -32,7 +32,7 @@ class Doctor private string $uuid; #[ORM\OneToOne(targetEntity: User::class)] - #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')] private User $user; #[ORM\Column(type: 'string', length: 255)] diff --git a/src/Insurance/Entity/DoctorInsurance.php b/src/Insurance/Entity/DoctorInsurance.php index 63daea88..9525cbba 100644 --- a/src/Insurance/Entity/DoctorInsurance.php +++ b/src/Insurance/Entity/DoctorInsurance.php @@ -22,7 +22,7 @@ class DoctorInsurance private Doctor $doctor; #[ORM\ManyToOne(targetEntity: Insurance::class)] - #[ORM\JoinColumn(name: 'insurance_id', referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(name: 'insurance_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] private Insurance $insurance; #[ORM\Column(type: 'integer', nullable: true)] diff --git a/src/Secretary/Entity/DoctorSecretary.php b/src/Secretary/Entity/DoctorSecretary.php index 897dbf5a..fc25874e 100644 --- a/src/Secretary/Entity/DoctorSecretary.php +++ b/src/Secretary/Entity/DoctorSecretary.php @@ -40,7 +40,7 @@ class DoctorSecretary private Doctor $doctor; #[ORM\ManyToOne(targetEntity: User::class)] - #[ORM\JoinColumn(name: 'secretary_id', referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(name: 'secretary_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] private User $secretary; #[ORM\Column(name: 'owner_type', type: 'string', length: 10, options: ['default' => 'doctor'])] diff --git a/src/Subscription/Entity/ClinicSubscription.php b/src/Subscription/Entity/ClinicSubscription.php index 9097727d..8a5d83c7 100644 --- a/src/Subscription/Entity/ClinicSubscription.php +++ b/src/Subscription/Entity/ClinicSubscription.php @@ -27,11 +27,11 @@ class ClinicSubscription private int $entityId; #[ORM\ManyToOne(targetEntity: SubscriptionPlan::class)] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: false, onDelete: 'RESTRICT')] private SubscriptionPlan $plan; #[ORM\ManyToOne(targetEntity: SubscriptionPeriod::class)] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: false, onDelete: 'RESTRICT')] private SubscriptionPeriod $period; #[ORM\ManyToOne(targetEntity: Payment::class)] diff --git a/src/Subscription/Entity/SubscriptionPeriod.php b/src/Subscription/Entity/SubscriptionPeriod.php index 1b4056af..17379673 100644 --- a/src/Subscription/Entity/SubscriptionPeriod.php +++ b/src/Subscription/Entity/SubscriptionPeriod.php @@ -19,7 +19,7 @@ class SubscriptionPeriod private string $uuid; #[ORM\ManyToOne(targetEntity: SubscriptionPlan::class, inversedBy: 'periods')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: false, onDelete: 'RESTRICT')] private SubscriptionPlan $plan; #[ORM\Column(type: 'string', length: 50)]