add new columns

This commit is contained in:
oleg.vodyanov91@gmail.com 2026-01-26 23:52:42 +04:00
parent a816b32a24
commit 079d90992a
2 changed files with 113 additions and 1 deletions

View File

@ -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 ###

View File

@ -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):
@ -210,3 +212,41 @@ class TariffsSettings(Base):
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())
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(),
)