Skip to content

Restart alembic versions with the table creation #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

madhav165
Copy link
Collaborator

@madhav165 madhav165 commented Jul 18, 2025

🐛 Bug-fix PR

📌 Summary

Identified the right way to do alembic migration. First migration script to have table creation commands.

💡 Fix Description

  • Base.metadata.create_all() replaced with command.upgrade(cfg, "head") set in gunicorn.config.py.
  • Also fixes tests that create multiple randomly named databases

🧪 Verification

Check Command Status
Lint suite make lint pass
Unit tests make test pass

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

Signed-off-by: Madhav Kandukuri <[email protected]>
@madhav165 madhav165 requested a review from crivetimihai as a code owner July 18, 2025 07:03
@crivetimihai crivetimihai changed the title Pending changes for alembic Signed-off-by: Madhav Kandukuri <[email protected]> Pending changes for alembic Jul 18, 2025
@madhav165 madhav165 marked this pull request as draft July 18, 2025 07:06
@madhav165 madhav165 marked this pull request as ready for review July 21, 2025 09:05
@madhav165 madhav165 self-assigned this Jul 21, 2025
@madhav165 madhav165 marked this pull request as draft July 21, 2025 14:38
madhav165 added 13 commits July 21, 2025 14:46
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
@madhav165 madhav165 marked this pull request as ready for review July 21, 2025 19:22
@madhav165 madhav165 requested a review from kevalmahajan as a code owner July 21, 2025 19:22
@madhav165 madhav165 changed the title Pending changes for alembic Restart alembic versions with the table creation Jul 21, 2025
@madhav165 madhav165 marked this pull request as draft July 21, 2025 19:33
@madhav165
Copy link
Collaborator Author

Having alembic migration on gunicorn startup works, tested with empty SQLite and PostgreSQL, however not optimal for CI/CD. Need to explore how to do it better for CI/CD.

Signed-off-by: Madhav Kandukuri <[email protected]>
@madhav165 madhav165 added this to the Release 0.5.0 milestone Jul 23, 2025
@crivetimihai
Copy link
Member

Fix the migration to be idempotent

In the migration file, wrap column additions in try/except or check existence

from sqlalchemy import inspect

def upgrade():
    bind = op.get_bind()
    inspector = inspect(bind)
    
    # Check if column exists before adding
    columns = [col['name'] for col in inspector.get_columns('gateways')]
    if 'slug' not in columns:
        op.add_column("gateways", sa.Column("slug", sa.String(), nullable=True))

Getting this:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: slug
[SQL: ALTER TABLE gateways ADD COLUMN slug VARCHAR]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

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.

2 participants