
- Setup project structure with FastAPI - Create database models for users, gifts, preferences, and recommendations - Configure SQLite database with SQLAlchemy ORM - Setup Alembic for database migrations - Implement user authentication with JWT - Create API endpoints for users, gifts, preferences, and recommendations - Integrate OpenAI API for gift recommendations - Add comprehensive documentation
127 lines
5.9 KiB
Python
127 lines
5.9 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2023-10-20
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create users table
|
|
op.create_table(
|
|
'users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
|
op.create_index(op.f('ix_users_full_name'), 'users', ['full_name'], unique=False)
|
|
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
|
|
|
# Create gifts table
|
|
op.create_table(
|
|
'gifts',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=True),
|
|
sa.Column('recipient_name', sa.String(), nullable=False),
|
|
sa.Column('relationship_to_user', sa.String(), nullable=True),
|
|
sa.Column('occasion', sa.String(), nullable=True),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('price', sa.Float(), nullable=True),
|
|
sa.Column('purchase_url', sa.String(), nullable=True),
|
|
sa.Column('purchased', sa.Boolean(), nullable=True, default=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_gifts_id'), 'gifts', ['id'], unique=False)
|
|
op.create_index(op.f('ix_gifts_name'), 'gifts', ['name'], unique=False)
|
|
op.create_index(op.f('ix_gifts_occasion'), 'gifts', ['occasion'], unique=False)
|
|
op.create_index(op.f('ix_gifts_recipient_name'), 'gifts', ['recipient_name'], unique=False)
|
|
op.create_index(op.f('ix_gifts_relationship_to_user'), 'gifts', ['relationship_to_user'], unique=False)
|
|
|
|
# Create preferences table
|
|
op.create_table(
|
|
'preferences',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=True),
|
|
sa.Column('recipient_name', sa.String(), nullable=False),
|
|
sa.Column('interests', sa.Text(), nullable=True),
|
|
sa.Column('hobbies', sa.Text(), nullable=True),
|
|
sa.Column('favorite_colors', sa.String(), nullable=True),
|
|
sa.Column('clothing_size', sa.String(), nullable=True),
|
|
sa.Column('dislikes', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_preferences_id'), 'preferences', ['id'], unique=False)
|
|
op.create_index(op.f('ix_preferences_recipient_name'), 'preferences', ['recipient_name'], unique=False)
|
|
|
|
# Create recommendations table
|
|
op.create_table(
|
|
'recommendations',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=True),
|
|
sa.Column('recipient_name', sa.String(), nullable=False),
|
|
sa.Column('occasion', sa.String(), nullable=True),
|
|
sa.Column('recommendation_text', sa.Text(), nullable=False),
|
|
sa.Column('item_name', sa.String(), nullable=True),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('price_estimate', sa.Float(), nullable=True),
|
|
sa.Column('purchase_url', sa.String(), nullable=True),
|
|
sa.Column('saved', sa.Boolean(), nullable=True, default=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_recommendations_id'), 'recommendations', ['id'], unique=False)
|
|
op.create_index(op.f('ix_recommendations_occasion'), 'recommendations', ['occasion'], unique=False)
|
|
op.create_index(op.f('ix_recommendations_recipient_name'), 'recommendations', ['recipient_name'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
# Drop recommendations table
|
|
op.drop_index(op.f('ix_recommendations_recipient_name'), table_name='recommendations')
|
|
op.drop_index(op.f('ix_recommendations_occasion'), table_name='recommendations')
|
|
op.drop_index(op.f('ix_recommendations_id'), table_name='recommendations')
|
|
op.drop_table('recommendations')
|
|
|
|
# Drop preferences table
|
|
op.drop_index(op.f('ix_preferences_recipient_name'), table_name='preferences')
|
|
op.drop_index(op.f('ix_preferences_id'), table_name='preferences')
|
|
op.drop_table('preferences')
|
|
|
|
# Drop gifts table
|
|
op.drop_index(op.f('ix_gifts_relationship_to_user'), table_name='gifts')
|
|
op.drop_index(op.f('ix_gifts_recipient_name'), table_name='gifts')
|
|
op.drop_index(op.f('ix_gifts_occasion'), table_name='gifts')
|
|
op.drop_index(op.f('ix_gifts_name'), table_name='gifts')
|
|
op.drop_index(op.f('ix_gifts_id'), table_name='gifts')
|
|
op.drop_table('gifts')
|
|
|
|
# Drop users table
|
|
op.drop_index(op.f('ix_users_id'), table_name='users')
|
|
op.drop_index(op.f('ix_users_full_name'), table_name='users')
|
|
op.drop_index(op.f('ix_users_email'), table_name='users')
|
|
op.drop_table('users') |