fixed migrations
This commit is contained in:
@@ -7,6 +7,7 @@ Create Date: 2024-03-19 10:00:00.000000
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@@ -18,7 +19,12 @@ depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# Create conversation table first
|
||||
op.create_table('conversation',
|
||||
conn = op.get_bind()
|
||||
inspector = inspect(conn)
|
||||
tables = inspector.get_table_names()
|
||||
|
||||
if 'conversation' not in tables:
|
||||
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),
|
||||
@@ -29,7 +35,12 @@ def upgrade():
|
||||
)
|
||||
|
||||
# Create conversation_members table
|
||||
op.create_table('conversation_members',
|
||||
conn = op.get_bind()
|
||||
inspector = inspect(conn)
|
||||
tables = inspector.get_table_names()
|
||||
|
||||
if 'conversation_members' not in tables:
|
||||
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'], ),
|
||||
@@ -38,7 +49,12 @@ def upgrade():
|
||||
)
|
||||
|
||||
# Create message table
|
||||
op.create_table('message',
|
||||
conn = op.get_bind()
|
||||
inspector = inspect(conn)
|
||||
tables = inspector.get_table_names()
|
||||
|
||||
if 'message' not in tables:
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user