From 611de1bf2abaca638793e36bc8225c10d1849bad Mon Sep 17 00:00:00 2001 From: deepvasoya Date: Mon, 26 May 2025 18:40:59 +0530 Subject: [PATCH] fix: clinic doc delete --- .../versions/a19fede0cdc6_relation_update.py | 38 +++++++++++++++++++ models/AppointmentRelations.py | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/a19fede0cdc6_relation_update.py diff --git a/migrations/versions/a19fede0cdc6_relation_update.py b/migrations/versions/a19fede0cdc6_relation_update.py new file mode 100644 index 0000000..46a01cd --- /dev/null +++ b/migrations/versions/a19fede0cdc6_relation_update.py @@ -0,0 +1,38 @@ +"""relation update + +Revision ID: a19fede0cdc6 +Revises: 48785e34c37c +Create Date: 2025-05-26 18:37:53.781411 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'a19fede0cdc6' +down_revision: Union[str, None] = '48785e34c37c' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint('appointment_relations_clinic_doctor_id_fkey', 'appointment_relations', type_='foreignkey') + op.create_foreign_key(None, 'appointment_relations', 'clinic_doctors', ['clinic_doctor_id'], ['id'], ondelete='CASCADE') + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('users', 'clinicRole', + existing_type=sa.Enum('DIRECTOR', 'PRACTICE_MANAGER', name='clinicuserroles'), + type_=sa.VARCHAR(), + existing_nullable=True) + op.drop_constraint(None, 'appointment_relations', type_='foreignkey') + op.create_foreign_key('appointment_relations_clinic_doctor_id_fkey', 'appointment_relations', 'clinic_doctors', ['clinic_doctor_id'], ['id']) + # ### end Alembic commands ### diff --git a/models/AppointmentRelations.py b/models/AppointmentRelations.py index 41094ec..78f4855 100644 --- a/models/AppointmentRelations.py +++ b/models/AppointmentRelations.py @@ -8,7 +8,7 @@ class AppointmentRelations(Base, CustomBase): id = Column(Integer, primary_key=True, index=True) appointment_type_id = Column(Integer, ForeignKey("master_appointment_types.id")) - clinic_doctor_id = Column(Integer, ForeignKey("clinic_doctors.id")) + clinic_doctor_id = Column(Integer, ForeignKey("clinic_doctors.id", ondelete="CASCADE")) clinicDoctors = relationship("ClinicDoctors", back_populates="appointmentRelations") masterAppointmentTypes = relationship("MasterAppointmentTypes", back_populates="appointmentRelations") \ No newline at end of file