Added messaging functions

This commit is contained in:
2025-05-26 15:11:26 +02:00
parent a497da8274
commit 9b8836183a
32 changed files with 1744 additions and 31 deletions

View File

@@ -0,0 +1,40 @@
"""add file attachment fields to message model
Revision ID: 0f48943140fa
Revises: bd04430cda95
Create Date: 2025-05-26 14:00:05.521776
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0f48943140fa'
down_revision = 'bd04430cda95'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.add_column(sa.Column('has_attachment', sa.Boolean(), nullable=True))
batch_op.add_column(sa.Column('attachment_name', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column('attachment_path', sa.String(length=512), nullable=True))
batch_op.add_column(sa.Column('attachment_type', sa.String(length=100), nullable=True))
batch_op.add_column(sa.Column('attachment_size', sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.drop_column('attachment_size')
batch_op.drop_column('attachment_type')
batch_op.drop_column('attachment_path')
batch_op.drop_column('attachment_name')
batch_op.drop_column('has_attachment')
# ### end Alembic commands ###

View 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')

View File

@@ -0,0 +1,24 @@
"""merge heads
Revision ID: bd04430cda95
Revises: f18735338888, add_conversations_tables
Create Date: 2025-05-26 11:14:05.629795
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bd04430cda95'
down_revision = ('f18735338888', 'add_conversations_tables')
branch_labels = None
depends_on = None
def upgrade():
pass
def downgrade():
pass

View File

@@ -0,0 +1,52 @@
"""add message attachments table and update message model
Revision ID: e7e4ff171f7a
Revises: 0f48943140fa
Create Date: 2025-05-26 15:00:18.557702
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e7e4ff171f7a'
down_revision = '0f48943140fa'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('message_attachment',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('message_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('path', sa.String(length=512), nullable=False),
sa.Column('type', sa.String(length=100), nullable=True),
sa.Column('size', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.drop_column('attachment_path')
batch_op.drop_column('attachment_type')
batch_op.drop_column('has_attachment')
batch_op.drop_column('attachment_size')
batch_op.drop_column('attachment_name')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.add_column(sa.Column('attachment_name', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
batch_op.add_column(sa.Column('attachment_size', sa.INTEGER(), autoincrement=False, nullable=True))
batch_op.add_column(sa.Column('has_attachment', sa.BOOLEAN(), autoincrement=False, nullable=True))
batch_op.add_column(sa.Column('attachment_type', sa.VARCHAR(length=100), autoincrement=False, nullable=True))
batch_op.add_column(sa.Column('attachment_path', sa.VARCHAR(length=512), autoincrement=False, nullable=True))
op.drop_table('message_attachment')
# ### end Alembic commands ###