From a893f6d490ab9dfdc74640312825fc2aaf2a8191 Mon Sep 17 00:00:00 2001 From: Ana Rute Mendes Date: Tue, 23 Jan 2024 16:10:28 +0100 Subject: [PATCH] api: add user details to User model --- .../0bee8c73c9a4_add_more_user_fields.py | 38 +++++++++++++++++++ api/models/user.py | 7 +++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 api/migrations/versions/0bee8c73c9a4_add_more_user_fields.py diff --git a/api/migrations/versions/0bee8c73c9a4_add_more_user_fields.py b/api/migrations/versions/0bee8c73c9a4_add_more_user_fields.py new file mode 100644 index 000000000..c61aa4be1 --- /dev/null +++ b/api/migrations/versions/0bee8c73c9a4_add_more_user_fields.py @@ -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 ### diff --git a/api/models/user.py b/api/models/user.py index 2a9e51edd..d858d170b 100644 --- a/api/models/user.py +++ b/api/models/user.py @@ -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 @@ -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()