вынес одинаковые поля в базовую модель
This commit is contained in:
parent
ee2f82d062
commit
c2d5407c22
@ -0,0 +1,92 @@
|
||||
"""Вынес одинаковые поля в базовую модель
|
||||
|
||||
Revision ID: 27fa11120115
|
||||
Revises: 70eb3c307702
|
||||
Create Date: 2025-02-20 09:51:06.021893
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '27fa11120115'
|
||||
down_revision: Union[str, None] = '70eb3c307702'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('appointment_files', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('appointment_files', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('appointment_types', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('appointment_types', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('appointments', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('appointments', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens_issues', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens_issues', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens_types', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('lens_types', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing_delivery_methods', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing_delivery_methods', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing_options', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('mailing_options', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('patients', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('patients', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('recipients', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('recipients', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('roles', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('roles', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('set_contents', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('set_contents', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('set_lens', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('set_lens', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('sets', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('sets', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('users', sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('users', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('users', 'updated_at')
|
||||
op.drop_column('users', 'created_at')
|
||||
op.drop_column('sets', 'updated_at')
|
||||
op.drop_column('sets', 'created_at')
|
||||
op.drop_column('set_lens', 'updated_at')
|
||||
op.drop_column('set_lens', 'created_at')
|
||||
op.drop_column('set_contents', 'updated_at')
|
||||
op.drop_column('set_contents', 'created_at')
|
||||
op.drop_column('roles', 'updated_at')
|
||||
op.drop_column('roles', 'created_at')
|
||||
op.drop_column('recipients', 'updated_at')
|
||||
op.drop_column('recipients', 'created_at')
|
||||
op.drop_column('patients', 'updated_at')
|
||||
op.drop_column('patients', 'created_at')
|
||||
op.drop_column('mailing_options', 'updated_at')
|
||||
op.drop_column('mailing_options', 'created_at')
|
||||
op.drop_column('mailing_delivery_methods', 'updated_at')
|
||||
op.drop_column('mailing_delivery_methods', 'created_at')
|
||||
op.drop_column('mailing', 'updated_at')
|
||||
op.drop_column('mailing', 'created_at')
|
||||
op.drop_column('lens_types', 'updated_at')
|
||||
op.drop_column('lens_types', 'created_at')
|
||||
op.drop_column('lens_issues', 'updated_at')
|
||||
op.drop_column('lens_issues', 'created_at')
|
||||
op.drop_column('lens', 'updated_at')
|
||||
op.drop_column('lens', 'created_at')
|
||||
op.drop_column('appointments', 'updated_at')
|
||||
op.drop_column('appointments', 'created_at')
|
||||
op.drop_column('appointment_types', 'updated_at')
|
||||
op.drop_column('appointment_types', 'created_at')
|
||||
op.drop_column('appointment_files', 'updated_at')
|
||||
op.drop_column('appointment_files', 'created_at')
|
||||
# ### end Alembic commands ###
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class AppointmentFile(Base):
|
||||
class AppointmentFile(BaseModel):
|
||||
__tablename__ = 'appointment_files'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
file_path = Column(String, nullable=False)
|
||||
file_title = Column(String, nullable=False)
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class AppointmentType(Base):
|
||||
class AppointmentType(BaseModel):
|
||||
__tablename__ = 'appointment_types'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
|
||||
appointments = relationship('Appointment', back_populates='type')
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Appointment(Base):
|
||||
class Appointment(BaseModel):
|
||||
__tablename__ = 'appointments'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
results = Column(String)
|
||||
days_until_the_next_appointment = Column(Integer)
|
||||
|
||||
|
||||
11
api/app/domain/models/base.py
Normal file
11
api/app/domain/models/base.py
Normal file
@ -0,0 +1,11 @@
|
||||
from sqlalchemy import Integer, Column, DateTime, func
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class BaseModel(Base):
|
||||
__abstract__ = True
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
created_at = Column(DateTime, server_default=func.now(), default=func.now, nullable=False)
|
||||
updated_at = Column(DateTime, server_default=func.now(), default=func.now, onupdate=func.now, nullable=False)
|
||||
@ -1,8 +1,9 @@
|
||||
from enum import Enum as PyEnum
|
||||
|
||||
from sqlalchemy import Column, Integer, ForeignKey, Float, Enum, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class SideEnum(PyEnum):
|
||||
@ -10,10 +11,9 @@ class SideEnum(PyEnum):
|
||||
RIGHT = 'правая'
|
||||
|
||||
|
||||
class Lens(Base):
|
||||
class Lens(BaseModel):
|
||||
__tablename__ = 'lens'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
tor = Column(Float, nullable=False)
|
||||
trial = Column(Float, nullable=False)
|
||||
esa = Column(Float, nullable=False)
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class LensIssue(Base):
|
||||
class LensIssue(BaseModel):
|
||||
__tablename__ = 'lens_issues'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
issue_date = Column(Date, nullable=False)
|
||||
|
||||
patient_id = Column(Integer, ForeignKey('patients.id'), nullable=False)
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class LensType(Base):
|
||||
class LensType(BaseModel):
|
||||
__tablename__ = 'lens_types'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
|
||||
lenses = relationship('Lens', back_populates='type')
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Mailing(Base):
|
||||
class Mailing(BaseModel):
|
||||
__tablename__ = 'mailing'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
text = Column(String, nullable=False)
|
||||
title = Column(String, nullable=False)
|
||||
datetime = Column(DateTime, nullable=False, default=func.utcnow)
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class MailingDeliveryMethod(Base):
|
||||
class MailingDeliveryMethod(BaseModel):
|
||||
__tablename__ = 'mailing_delivery_methods'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(200), nullable=False)
|
||||
|
||||
mailing = relationship('MailingOption', back_populates='method')
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class MailingOption(Base):
|
||||
class MailingOption(BaseModel):
|
||||
__tablename__ = 'mailing_options'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
option_id = Column(Integer, ForeignKey('mailing_delivery_methods.id'), nullable=False)
|
||||
mailing_id = Column(Integer, ForeignKey('mailing.id'), nullable=False)
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR, Date, String
|
||||
from sqlalchemy import Column, VARCHAR, Date, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Patient(Base):
|
||||
class Patient(BaseModel):
|
||||
__tablename__ = 'patients'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
first_name = Column(VARCHAR(200), nullable=False)
|
||||
last_name = Column(VARCHAR(200), nullable=False)
|
||||
patronymic = Column(VARCHAR(200))
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Recipient(Base):
|
||||
class Recipient(BaseModel):
|
||||
__tablename__ = 'recipients'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
patient_id = Column(Integer, ForeignKey('patients.id'), nullable=False)
|
||||
mailing_id = Column(Integer, ForeignKey('mailing.id'), nullable=False)
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Role(Base):
|
||||
class Role(BaseModel):
|
||||
__tablename__ = 'roles'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
|
||||
users = relationship('User', back_populates='role')
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class SetContent(Base):
|
||||
class SetContent(BaseModel):
|
||||
__tablename__ = 'set_contents'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
tor = Column(Integer, nullable=False)
|
||||
trial = Column(Integer, nullable=False)
|
||||
esa = Column(Integer, nullable=False)
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class SetLens(Base):
|
||||
class SetLens(BaseModel):
|
||||
__tablename__ = 'set_lens'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
set_id = Column(Integer, ForeignKey('sets.id'), nullable=False)
|
||||
lens_id = Column(Integer, ForeignKey('lens.id'), nullable=False, unique=True)
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class Set(Base):
|
||||
class Set(BaseModel):
|
||||
__tablename__ = 'sets'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
count = Column(Integer, nullable=False)
|
||||
|
||||
|
||||
@ -2,13 +2,12 @@ from sqlalchemy import Column, Integer, VARCHAR, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
from app.domain.models import Base
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
|
||||
class User(Base):
|
||||
class User(BaseModel):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
first_name = Column(VARCHAR(200), nullable=False)
|
||||
last_name = Column(VARCHAR(200), nullable=False)
|
||||
patronymic = Column(VARCHAR(200))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user