diff --git a/app/models/__init__.py b/app/models/__init__.py index 68d5cd5..bc43d51 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -1 +1,2 @@ -from app.models.base import Base \ No newline at end of file +from app.models.base import Base +from app.models.message import Message \ No newline at end of file diff --git a/app/models/message.py b/app/models/message.py new file mode 100644 index 0000000..6f721e9 --- /dev/null +++ b/app/models/message.py @@ -0,0 +1,15 @@ +from datetime import datetime +from sqlalchemy import Column, Integer, String, DateTime, Boolean + +from app.models.base import Base + + +class Message(Base): + __tablename__ = "messages" + + id = Column(Integer, primary_key=True, index=True) + sender = Column(String, nullable=False) + recipient = Column(String, nullable=False) + content = Column(String, nullable=False) + timestamp = Column(DateTime, default=datetime.utcnow) + is_read = Column(Boolean, default=False) \ No newline at end of file diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py index e69de29..787ddd4 100644 --- a/app/schemas/__init__.py +++ b/app/schemas/__init__.py @@ -0,0 +1 @@ +from app.schemas.message import MessageBase, MessageCreate, MessageResponse \ No newline at end of file diff --git a/app/schemas/message.py b/app/schemas/message.py new file mode 100644 index 0000000..9de6d2c --- /dev/null +++ b/app/schemas/message.py @@ -0,0 +1,22 @@ +from datetime import datetime +from typing import Optional +from pydantic import BaseModel + + +class MessageBase(BaseModel): + sender: str + recipient: str + content: str + + +class MessageCreate(MessageBase): + pass + + +class MessageResponse(MessageBase): + id: int + timestamp: datetime + is_read: bool + + class Config: + orm_mode = True \ No newline at end of file diff --git a/migrations/versions/add_message_model.py b/migrations/versions/add_message_model.py new file mode 100644 index 0000000..4a11fd2 --- /dev/null +++ b/migrations/versions/add_message_model.py @@ -0,0 +1,38 @@ +"""Add Message model + +Revision ID: add_message_model +Revises: initial_migration +Create Date: 2025-06-05 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'add_message_model' +down_revision = 'initial_migration' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('messages', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('sender', sa.String(), nullable=False), + sa.Column('recipient', sa.String(), nullable=False), + sa.Column('content', sa.String(), nullable=False), + sa.Column('timestamp', sa.DateTime(), nullable=True), + sa.Column('is_read', sa.Boolean(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_messages_id'), 'messages', ['id'], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_messages_id'), table_name='messages') + op.drop_table('messages') + # ### end Alembic commands ### \ No newline at end of file