最初に、Flask-Migrate を使用してスキーマ マイグレーションを作成します (Flask の Alembic マイグレーション)。その後、別のデータ移行スクリプトを作成します (Flask-Migrate も使用)。しかし、./manage db upgrade
適用されていないすべての移行を適用するために実行すると、コンソール出力に、適用されたスキーマの移行が表示されますが、データの移行は適用されず、ハング状態のプロセスが表示されます。移行のプロセスを強制終了した後、スキーマの移行もデータの移行も適用されていない DB が表示されます。しかし、 や などのコマンドを使用して 1 つずつ移行を実行する/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
1 つのコマンドでデータベースをアップグレードするにはどうすればよいですか?