27 lines
1.3 KiB
Python

Here's the `user.py` file for the `app/api/v1/models/` directory in the `blog_app` FastAPI backend:
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from app.api.db.database import Base
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True, nullable=False)
email = Column(String, unique=True, nullable=False)
password_hash = Column(String, nullable=False)
full_name = Column(String)
bio = Column(Text)
profile_pic = Column(String)
Explanation:
1. We import the necessary classes from `sqlalchemy` for defining the database columns: `Column`, `ForeignKey`, `Integer`, `String`, and `Text`.
5. We define the following columns for the `User` model:
- `id`: An integer primary key column with an index.
- `username`: A string column that must be unique and cannot be null.
- `email`: A string column that must be unique and cannot be null.
- `password_hash`: A string column that cannot be null (for storing the hashed password).
- `full_name`: An optional string column for the user's full name.
- `bio`: An optional text column for the user's biography.
- `profile_pic`: An optional string column for the user's profile picture URL.