Add Message model and schema with migration
This commit is contained in:
parent
c64d65ebc8
commit
f434ee6ab3
@ -1 +1,2 @@
|
||||
from app.models.base import Base
|
||||
from app.models.base import Base
|
||||
from app.models.message import Message
|
15
app/models/message.py
Normal file
15
app/models/message.py
Normal file
@ -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)
|
@ -0,0 +1 @@
|
||||
from app.schemas.message import MessageBase, MessageCreate, MessageResponse
|
22
app/schemas/message.py
Normal file
22
app/schemas/message.py
Normal file
@ -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
|
38
migrations/versions/add_message_model.py
Normal file
38
migrations/versions/add_message_model.py
Normal file
@ -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 ###
|
Loading…
x
Reference in New Issue
Block a user