From 079d90992a58286566249fb4adbfb7885c825807 Mon Sep 17 00:00:00 2001 From: "oleg.vodyanov91@gmail.com" Date: Mon, 26 Jan 2026 23:52:42 +0400 Subject: [PATCH] add new columns --- ...5d87ddeb_new_tables_for_doctor_payments.py | 72 +++++++++++++++++++ src/db/models.py | 42 ++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/af035d87ddeb_new_tables_for_doctor_payments.py diff --git a/alembic/versions/af035d87ddeb_new_tables_for_doctor_payments.py b/alembic/versions/af035d87ddeb_new_tables_for_doctor_payments.py new file mode 100644 index 0000000..e65d200 --- /dev/null +++ b/alembic/versions/af035d87ddeb_new_tables_for_doctor_payments.py @@ -0,0 +1,72 @@ +"""new tables for doctor payments + +Revision ID: af035d87ddeb +Revises: d252e6046fda +Create Date: 2026-01-11 22:29:45.201498 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'af035d87ddeb' +down_revision: Union[str, None] = 'd252e6046fda' +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.create_table('tariffs_settings', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('name', sa.String(length=100), nullable=False), + sa.Column('description', sa.Text(), nullable=True), + sa.Column('price', sa.Numeric(precision=12, scale=2), nullable=False), + sa.Column('consultation_count', sa.Integer(), nullable=False), + sa.Column('duration_days', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + op.create_table('doctor_payments', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('doctor_id', sa.Integer(), nullable=False), + sa.Column('tariff_id', sa.Integer(), nullable=False), + sa.Column('external_payment_id', sa.String(), nullable=False), + sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False), + sa.Column('status', sa.String(), nullable=False), + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), + sa.ForeignKeyConstraint(['doctor_id'], ['doctors.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tariff_id'], ['tariffs_settings.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('doctor_subscriptions', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('doctor_id', sa.Integer(), nullable=False), + sa.Column('tariff_id', sa.Integer(), nullable=False), + sa.Column('started_at', sa.DateTime(), nullable=False), + sa.Column('expires_at', sa.DateTime(), nullable=False), + sa.Column('is_active', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['doctor_id'], ['doctors.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tariff_id'], ['tariffs_settings.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('doctor_id') + ) + op.add_column('admins', sa.Column('owner', sa.Boolean(), nullable=False, server_default=sa.text('false'))) + op.add_column('admins', sa.Column('payment_link', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('admins', 'payment_link') + op.drop_column('admins', 'owner') + op.drop_table('doctor_subscriptions') + op.drop_table('doctor_payments') + op.drop_table('tariffs_settings') + # ### end Alembic commands ### diff --git a/src/db/models.py b/src/db/models.py index d8a7562..3a9516e 100644 --- a/src/db/models.py +++ b/src/db/models.py @@ -63,6 +63,8 @@ class Admins(Base): created_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True) available_payment_methods: Mapped[Optional[List[str]]] = mapped_column( ARRAY(String), nullable=True) + owner: Mapped[bool] = mapped_column(default=False, nullable=False) + payment_link: Mapped[Optional[str]] = mapped_column(nullable=True) class Patients(Base): @@ -209,4 +211,42 @@ class TariffsSettings(Base): price: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False) consultation_count: Mapped[int] = mapped_column(nullable=False) duration_days: Mapped[int] = mapped_column(nullable=False) - created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now()) \ No newline at end of file + created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now()) + + +class DoctorSubscription(Base): + __tablename__ = "doctor_subscriptions" + + id: Mapped[int] = mapped_column(primary_key=True) + doctor_id: Mapped[int] = mapped_column( + ForeignKey("doctors.id", ondelete="CASCADE"), + unique=True, + ) + tariff_id: Mapped[int] = mapped_column( + ForeignKey("tariffs_settings.id") + ) + started_at: Mapped[datetime] + expires_at: Mapped[datetime] + is_active: Mapped[bool] = mapped_column(default=True) + + doctor: Mapped["Doctors"] = relationship() + tariff: Mapped["TariffsSettings"] = relationship() + + +class DoctorPayments(Base): + __tablename__ = "doctor_payments" + + id: Mapped[int] = mapped_column(primary_key=True) + doctor_id: Mapped[int] = mapped_column( + ForeignKey("doctors.id", ondelete="CASCADE") + ) + tariff_id: Mapped[int] = mapped_column( + ForeignKey("tariffs_settings.id") + ) + external_payment_id: Mapped[str] + amount: Mapped[Decimal] = mapped_column(Numeric(12, 2)) + status: Mapped[str] # pending / success / failed + created_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), + server_default=func.now(), + ) \ No newline at end of file