Skip to content

Commit

Permalink
api: add user details to User model
Browse files Browse the repository at this point in the history
  • Loading branch information
anarute committed Feb 12, 2024
1 parent 06c2081 commit a893f6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions api/migrations/versions/0bee8c73c9a4_add_more_user_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""add more user fields
Revision ID: 0bee8c73c9a4
Revises: fb8c0e665690
Create Date: 2024-01-23 10:54:52.530939
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0bee8c73c9a4'
down_revision = 'fb8c0e665690'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('usr', sa.Column('email', sa.String(length=100), nullable=True))
op.add_column('usr', sa.Column('first_name', sa.String(length=100), nullable=True))
op.add_column('usr', sa.Column('last_name', sa.String(length=100), nullable=True))
op.add_column('usr', sa.Column('avatar_url', sa.String(length=500), nullable=True))
op.add_column('usr', sa.Column('is_active', sa.Boolean()))
op.create_unique_constraint('uq_user_email', 'usr', ['email'])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('uq_user_email', 'usr', type_='unique')
op.drop_column('usr', 'is_active')
op.drop_column('usr', 'last_name')
op.drop_column('usr', 'first_name')
op.drop_column('usr', 'email')
op.drop_column('usr', 'avatar_url')
# ### end Alembic commands ###
7 changes: 6 additions & 1 deletion api/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
from sqlalchemy import Date, Column, ForeignKey, Integer, String, Numeric, UniqueConstraint, CheckConstraint
from sqlalchemy import Boolean, Date, Column, ForeignKey, Integer, String, Numeric, UniqueConstraint, CheckConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy.ext.hybrid import hybrid_property
Expand All @@ -13,6 +13,11 @@ class User(Base):
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
password = Column(String(length=256), nullable=True)
login = Column(String(length=100), nullable=False, unique=True)
email = Column(String(length=100), unique=True)
first_name = Column(String(length=100))
last_name = Column(String(length=100))
avatar_url = Column(String(length=500))
is_active = Column(Boolean, default=True)
capacities: Mapped[List["UserCapacity"]] = relationship()


Expand Down

0 comments on commit a893f6d

Please sign in to comment.