Skip to content

Conversation

@nmveeresh
Copy link
Collaborator

Bootstrap Role Assignment Fix

Overview

This update fixes a bug in the bootstrap process where assigning the platform_admin role to the admin user fails due to a foreign key constraint violation. Previously, the granted_by field was set to "system", which violates the FK constraint referencing email_users.email.

Changes

  • Modified mcpgateway/bootstrap_db.py to use the admin user's email for self-assignment during bootstrap:
await role_service.assign_role_to_user(
    user_email=admin_user.email,
    role_id=platform_admin_role.id,
    scope="global",
    scope_id=None,
    granted_by=admin_user.email  # Use admin email instead of "system"
)
  • Modified mcpgateway/db.py to reduce the url column length from String(767) to VARCHAR(191) to prevent MySQL index size errors:
class Gateway(Base):
    """ORM model for a federated peer Gateway."""

    __tablename__ = "gateways"

    id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: uuid.uuid4().hex)
    name: Mapped[str] = mapped_column(String(255), nullable=False)
    slug: Mapped[str] = mapped_column(VARCHAR(191), nullable=False) # from String(767) to VARCHAR(191)
    url: Mapped[str] = mapped_column(VARCHAR(191), nullable=False) # from String(767) to VARCHAR(191)

Impact

  • Fixes foreign key constraint violation during bootstrap by using a valid granted_by email.
  • Ensures the admin user is automatically assigned the platform_admin role during bootstrap.
  • Prevents MySQL index size errors by reducing column length for slug and url fields.

Testing

  • Verified successful bootstrap on MySQL with strict foreign key constraints enabled.
  • Confirmed that the admin user is correctly assigned the platform_admin role.
  • Validated that the schema creation completes without index size errors.

@nmveeresh nmveeresh marked this pull request as ready for review October 7, 2025 05:10
@madhav165 madhav165 force-pushed the issue-926/bootstrap-platform-admin-fk-fix branch from c0af6fb to cdf8466 Compare October 7, 2025 13:49
Copy link
Collaborator

@madhav165 madhav165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nmveeresh , the functionality for changing the length of URL and slug column needs to be accompanied with an alembic script so that the existing columns are also resized. Currently, it creates smaller columns in Gateways table when the db is empty, but does not resize when the table is already present.

Can you split this PR into two? One just for the PK fix and a separate PR for the key length change along with the alembic script?

Signed-off-by: Madhav Kandukuri <[email protected]>
Copy link
Collaborator

@madhav165 madhav165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted changes to slug and url lengths in gateways table. Those will be part of a separate PR. This can be merged.

@crivetimihai crivetimihai merged commit 1f54133 into main Oct 7, 2025
36 checks passed
@crivetimihai crivetimihai deleted the issue-926/bootstrap-platform-admin-fk-fix branch October 7, 2025 16:18
@crivetimihai crivetimihai mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bootstrap fails to assign platform_admin role due to foreign key constraint violation

4 participants