217 lines
11 KiB
Python
217 lines
11 KiB
Python
"""0001_инициализация
|
||
|
||
Revision ID: b10579618fb5
|
||
Revises:
|
||
Create Date: 2025-03-11 14:37:52.604086
|
||
|
||
"""
|
||
from typing import Sequence, Union
|
||
|
||
from alembic import op
|
||
import sqlalchemy as sa
|
||
|
||
|
||
# revision identifiers, used by Alembic.
|
||
revision: str = 'b10579618fb5'
|
||
down_revision: Union[str, None] = None
|
||
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.create_table('appointment_types',
|
||
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id'),
|
||
sa.UniqueConstraint('title')
|
||
)
|
||
op.create_table('lens_types',
|
||
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id'),
|
||
sa.UniqueConstraint('title')
|
||
)
|
||
op.create_table('mailing_delivery_methods',
|
||
sa.Column('title', sa.VARCHAR(length=200), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('patients',
|
||
sa.Column('first_name', sa.VARCHAR(length=200), nullable=False),
|
||
sa.Column('last_name', sa.VARCHAR(length=200), nullable=False),
|
||
sa.Column('patronymic', sa.VARCHAR(length=200), nullable=True),
|
||
sa.Column('birthday', sa.Date(), nullable=False),
|
||
sa.Column('address', sa.String(), nullable=True),
|
||
sa.Column('email', sa.VARCHAR(length=350), nullable=True),
|
||
sa.Column('phone', sa.VARCHAR(length=25), nullable=True),
|
||
sa.Column('diagnosis', sa.String(), nullable=True),
|
||
sa.Column('correction', sa.String(), nullable=True),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('roles',
|
||
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id'),
|
||
sa.UniqueConstraint('title')
|
||
)
|
||
op.create_table('sets',
|
||
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.PrimaryKeyConstraint('id'),
|
||
sa.UniqueConstraint('title')
|
||
)
|
||
op.create_table('lens',
|
||
sa.Column('tor', sa.Float(), nullable=False),
|
||
sa.Column('trial', sa.Float(), nullable=False),
|
||
sa.Column('esa', sa.Float(), nullable=False),
|
||
sa.Column('fvc', sa.Float(), nullable=False),
|
||
sa.Column('preset_refraction', sa.Float(), nullable=False),
|
||
sa.Column('diameter', sa.Float(), nullable=False),
|
||
sa.Column('periphery_toricity', sa.Float(), nullable=False),
|
||
sa.Column('side', sa.Enum('LEFT', 'RIGHT', name='sideenum'), nullable=False),
|
||
sa.Column('issued', sa.Boolean(), nullable=False),
|
||
sa.Column('type_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['type_id'], ['lens_types.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('set_contents',
|
||
sa.Column('tor', sa.Float(), nullable=False),
|
||
sa.Column('trial', sa.Float(), nullable=False),
|
||
sa.Column('esa', sa.Float(), nullable=False),
|
||
sa.Column('fvc', sa.Float(), nullable=False),
|
||
sa.Column('preset_refraction', sa.Float(), nullable=False),
|
||
sa.Column('diameter', sa.Float(), nullable=False),
|
||
sa.Column('periphery_toricity', sa.Float(), nullable=False),
|
||
sa.Column('side', sa.Enum('LEFT', 'RIGHT', name='sideenum'), nullable=False),
|
||
sa.Column('count', sa.Integer(), nullable=False),
|
||
sa.Column('type_id', sa.Integer(), nullable=False),
|
||
sa.Column('set_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['set_id'], ['sets.id'], ),
|
||
sa.ForeignKeyConstraint(['type_id'], ['lens_types.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('users',
|
||
sa.Column('first_name', sa.VARCHAR(length=200), nullable=False),
|
||
sa.Column('last_name', sa.VARCHAR(length=200), nullable=False),
|
||
sa.Column('patronymic', sa.VARCHAR(length=200), nullable=True),
|
||
sa.Column('login', sa.String(), nullable=False),
|
||
sa.Column('password', sa.String(), nullable=False),
|
||
sa.Column('role_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
|
||
sa.PrimaryKeyConstraint('id'),
|
||
sa.UniqueConstraint('login')
|
||
)
|
||
op.create_table('appointments',
|
||
sa.Column('results', sa.String(), nullable=True),
|
||
sa.Column('days_until_the_next_appointment', sa.Integer(), nullable=True),
|
||
sa.Column('date', sa.Date(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||
sa.Column('doctor_id', sa.Integer(), nullable=False),
|
||
sa.Column('type_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['doctor_id'], ['users.id'], ),
|
||
sa.ForeignKeyConstraint(['patient_id'], ['patients.id'], ),
|
||
sa.ForeignKeyConstraint(['type_id'], ['appointment_types.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('lens_issues',
|
||
sa.Column('issue_date', sa.Date(), nullable=False),
|
||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||
sa.Column('doctor_id', sa.Integer(), nullable=False),
|
||
sa.Column('lens_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['doctor_id'], ['users.id'], ),
|
||
sa.ForeignKeyConstraint(['lens_id'], ['lens.id'], ),
|
||
sa.ForeignKeyConstraint(['patient_id'], ['patients.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('mailing',
|
||
sa.Column('text', sa.String(), nullable=False),
|
||
sa.Column('title', sa.String(), nullable=False),
|
||
sa.Column('datetime', sa.DateTime(), nullable=False),
|
||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('appointment_files',
|
||
sa.Column('file_path', sa.String(), nullable=False),
|
||
sa.Column('file_title', sa.String(), nullable=False),
|
||
sa.Column('appointment_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['appointment_id'], ['appointments.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('mailing_options',
|
||
sa.Column('option_id', sa.Integer(), nullable=False),
|
||
sa.Column('mailing_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['mailing_id'], ['mailing.id'], ),
|
||
sa.ForeignKeyConstraint(['option_id'], ['mailing_delivery_methods.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
op.create_table('recipients',
|
||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||
sa.Column('mailing_id', sa.Integer(), nullable=False),
|
||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
|
||
sa.ForeignKeyConstraint(['mailing_id'], ['mailing.id'], ),
|
||
sa.ForeignKeyConstraint(['patient_id'], ['patients.id'], ),
|
||
sa.PrimaryKeyConstraint('id')
|
||
)
|
||
# ### end Alembic commands ###
|
||
|
||
|
||
def downgrade() -> None:
|
||
# ### commands auto generated by Alembic - please adjust! ###
|
||
op.drop_table('recipients')
|
||
op.drop_table('mailing_options')
|
||
op.drop_table('appointment_files')
|
||
op.drop_table('mailing')
|
||
op.drop_table('lens_issues')
|
||
op.drop_table('appointments')
|
||
op.drop_table('users')
|
||
op.drop_table('set_contents')
|
||
op.drop_table('lens')
|
||
op.drop_table('sets')
|
||
op.drop_table('roles')
|
||
op.drop_table('patients')
|
||
op.drop_table('mailing_delivery_methods')
|
||
op.drop_table('lens_types')
|
||
op.drop_table('appointment_types')
|
||
# ### end Alembic commands ###
|