Added messaging functions
This commit is contained in:
57
migrations/versions/add_conversations_tables.py
Normal file
57
migrations/versions/add_conversations_tables.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Add conversations and messages tables
|
||||
|
||||
Revision ID: add_conversations_tables
|
||||
Revises: 2c5f57dddb78
|
||||
Create Date: 2024-03-19 10:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_conversations_tables'
|
||||
down_revision = '2c5f57dddb78'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Create conversation table first
|
||||
op.create_table('conversation',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_by', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Create conversation_members table
|
||||
op.create_table('conversation_members',
|
||||
sa.Column('conversation_id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('conversation_id', 'user_id')
|
||||
)
|
||||
|
||||
# Create message table
|
||||
op.create_table('message',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('content', sa.Text(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('conversation_id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
# Drop tables in reverse order
|
||||
op.drop_table('message')
|
||||
op.drop_table('conversation_members')
|
||||
op.drop_table('conversation')
|
||||
Reference in New Issue
Block a user