ba-thesis/backend/database/migrations/versions/335e07a98bc8_create_user_tables.py

51 lines
1.5 KiB
Python
Raw Normal View History

"""create user tables
Revision ID: 335e07a98bc8
Revises:
Create Date: 2023-05-12 19:59:22.188464
"""
from alembic import op
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Date, Enum, CheckConstraint
from sqlalchemy.sql.functions import now
from backend.models.users import Gender
# revision identifiers, used by Alembic.
revision = '335e07a98bc8'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
'users',
Column('id', Integer, primary_key=True, autoincrement=True, index=True),
Column('email', String, unique=True, nullable=False),
Column('password', String, nullable=False),
Column('created', DateTime(timezone=True), nullable=False, server_default=now()),
Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now()),
Column('first_name', String, nullable=False),
Column('last_name', String, nullable=False),
)
op.create_table(
'administrators',
Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE"), primary_key=True,)
)
op.create_table(
'patients',
Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE"), primary_key=True),
Column('date_of_birth', Date, nullable=False),
Column('gender', Enum(Gender), nullable=False),
)
def downgrade() -> None:
op.drop_table('users')
op.drop_table('administrators')
op.drop_table('patients')