2

首先,我使用 Flask-Migrate(Flask 的 Alembic 迁移)创建模式迁移。之后,我创建了单独的数据迁移脚本(也使用了 Flask-Migrate)。但是当我运行./manage db upgrade应用所有未应用的迁移时,我在控制台输出中看到应用了哪些模式迁移,但没有数据迁移,并且进程处于挂起状态。杀死迁移过程后,我在数据库中看到,既没有架构迁移,也没有应用数据迁移。/manage.py db upgrade <schema_migration_revision>但是,当我使用和之类的命令逐个运行迁移时./manage db upgrade <data_migration_revision>,所有迁移都毫无问题地应用了。

架构迁移:

"""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 ###

数据迁移:

"""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

如何用一个命令升级数据库?

4

0 回答 0