Skip to content

This is example of working with alembic, sqlalchemy and asyncpg

Notifications You must be signed in to change notification settings

supadrupa/dbalc

Repository files navigation

dbalc: This is example of working with alembic, sqlalchemy and asyncpg

pip install alembic
alembic init migrations

PYTHONPATH=. alembic revision -m "commit"

PYTHONPATH=. alembic revision --autogenerate -m "commit"

PYTHONPATH=. alembic upgrade head

Какие изменения autogenerate может не заметить https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect

Стандартная заготовка миграции для алембика

"""create account table

Revision ID: 1975ea83b712
Revises:
Create Date: 2011-11-08 11:40:27.089406

"""

# revision identifiers, used by Alembic.
revision = '1975ea83b712'
down_revision = None
branch_labels = None

from alembic import op
import sqlalchemy as sa

def upgrade():
    pass

def downgrade():
    pass

Как может выглядеть миграция

"""create account table

Revision ID: 1975ea83b712
Revises:
Create Date: 2011-11-08 11:40:27.089406

"""

# revision identifiers, used by Alembic.
revision = '1975ea83b712'
down_revision = None
branch_labels = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'account',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('name', sa.String(50), nullable=False),
        sa.Column('description', sa.Unicode(200)),
    )

def downgrade():
    op.drop_table('account')

схема для миграции описывается через sqlalchemy

About

This is example of working with alembic, sqlalchemy and asyncpg

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages