fix(db): declare onDelete on required FKs that had none
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.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?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 Version20260628133044 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add ON DELETE CASCADE to doctor_insurances.insurance_id and doctor_secretaries.secretary_id (required FKs that had no referential action). The RESTRICT FKs added in the same change (Doctor/Clinic.user_id, invited_by_id, subscription plan/period) need no DDL — RESTRICT is the MySQL default.';
|
||||
}
|
||||
|
||||
public function up(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) 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)');
|
||||
}
|
||||
}
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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'])]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user