/alembic-sqlmodel

Example of using Alembic with the SQLModel ORM.

Primary LanguagePython

Alembic + SQLModel

natorsc - alembic-sqlmodel stars - alembic-sqlmodel forks - alembic-sqlmodel License MIT

✨ About this project

Example of using Alembic with the SQLModel ORM.

If this content has helped you, please consider making a donation. Your support makes a real difference and helps the project grow! 💙

🛠 Technologies used

Python Alembic SQLModel uv

👨‍💻 Author

Crafted with 💙 by Renato Cruz. Got questions or feedback? Reach out anytime!

Email

What I'm listening to while I code or study 😎🎵:

Spotify

💝 Support This Project

Your donation keeps this project alive and helps me continue creating and sharing useful content.

GitHub Sponsors

https://github.com/sponsors/natorsc/

Pix (Brazil)

b1839493-2afe-484d-9272-82a3e402b36f


Errors

NameError: name 'sqlmodel' is not defined.

To fix the error:

sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=30), nullable=False),
                  ^^^^^^^^
NameError: name 'sqlmodel' is not defined.

Import the sqlmodel into the script.py.mako file.

Example:

"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
# To fix the error:
# sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=30), nullable=False),
#                    ^^^^^^^^
# NameError: name 'sqlmodel' is not defined.
import sqlmodel
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}


def upgrade() -> None:
    """Upgrade schema."""
    ${upgrades if upgrades else "pass"}


def downgrade() -> None:
    """Downgrade schema."""
    ${downgrades if downgrades else "pass"}