more robust migrations

This commit is contained in:
2025-06-02 18:58:48 +02:00
parent 4dbaa27cba
commit 5c6c3f436e
51 changed files with 401 additions and 273 deletions

View File

@@ -19,51 +19,51 @@ depends_on = None
def upgrade():
# Create conversation table first
conn = op.get_bind()
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),
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')
)
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
conn = op.get_bind()
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'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('conversation_id', 'user_id')
)
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
conn = op.get_bind()
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),
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')
)
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():