2

At first I create schema migration with Flask-Migrate (Alembic migrations for Flask). After that, I create separated data migration script (with Flask-Migrate too). But when I run ./manage db upgrade for apply all not-applied migrations, I see in console output, what schema migration applied, but data migration do not, and process in hanging state. After killing process of migration, I see in DB, what neither schema migration, nor data migration not applied. But when I run migrations by one with commands like /manage.py db upgrade <schema_migration_revision> and ./manage db upgrade <data_migration_revision>, then all migrations applied without problems.

Schema migration:

"""empty message

Revision ID: 131f25f3304b
Revises: cdb88398744
Create Date: 2015-11-30 14:41:50.522876

"""

# revision identifiers, used by Alembic.
revision = '131f25f3304b'
down_revision = '4d422a836640'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('table_to_field', sa.Column('noagg_sql', sa.String()))
    op.add_column('table_to_field', sa.Column('subquery_noagg_sql', sa.String()))
    op.add_column('table_to_field', sa.Column('subquery_sql', sa.String()))
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('table_to_field', 'subquery_sql')
    op.drop_column('table_to_field', 'subquery_noagg_sql')
    op.drop_column('table_to_field', 'noagg_sql')
    ### end Alembic commands ###

Data migration:

"""empty message

Revision ID: 543705754315
Revises: 131f25f3304b
Create Date: 2015-12-01 17:06:31.778978

"""

# revision identifiers, used by Alembic.
revision = '543705754315'
down_revision = '131f25f3304b'

from alembic import op
import sqlalchemy as sa


def upgrade():
    from core.db import fixtures
    from core.db.model import TableField, Table
    from app import db

    for tf in TableField.query.all():
        tf.noagg_sql = 'some value'
        tf.subquery_sql = 'some value'
        tf.subquery_noagg_sql = 'some value'

    db.session.commit()


def downgrade():
    pass

How do upgrade data base with one command?

0 Answers0