
Features: - Extended User model with profile fields (first_name, last_name, phone, bio, preferred_language, timezone) - Complete profile endpoints for viewing and updating user information - Password update functionality with current password verification - Email update functionality with duplicate email checking - Account deletion endpoint - Database migration for new profile fields - Enhanced logging and error handling for all profile operations - Updated API documentation with profile endpoints Profile fields include: - Personal information (name, phone, bio) - Preferences (language, timezone) - Account management (password, email updates) - Timestamps (created_at, updated_at)
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""Add profile fields to users table
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2024-01-01 00:00:01.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '002'
|
|
down_revision: Union[str, None] = '001'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Add new profile fields to users table
|
|
op.add_column('users', sa.Column('first_name', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('last_name', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('phone', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('bio', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('preferred_language', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('timezone', sa.String(), nullable=True))
|
|
op.add_column('users', sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True))
|
|
|
|
# Set default values for existing users
|
|
op.execute("UPDATE users SET preferred_language = 'en' WHERE preferred_language IS NULL")
|
|
op.execute("UPDATE users SET timezone = 'UTC' WHERE timezone IS NULL")
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Remove the added columns
|
|
op.drop_column('users', 'updated_at')
|
|
op.drop_column('users', 'timezone')
|
|
op.drop_column('users', 'preferred_language')
|
|
op.drop_column('users', 'bio')
|
|
op.drop_column('users', 'phone')
|
|
op.drop_column('users', 'last_name')
|
|
op.drop_column('users', 'first_name') |