mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-09 15:10:27 +00:00
Support SQLite ALTER with batch feature during alembic migrate
Fix #404
This commit is contained in:
parent
2f39512b65
commit
94becb35c6
@ -73,6 +73,7 @@ def run_migrations_online():
|
|||||||
context.configure(connection=connection,
|
context.configure(connection=connection,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
process_revision_directives=process_revision_directives,
|
process_revision_directives=process_revision_directives,
|
||||||
|
render_as_batch=config.get_main_option('sqlalchemy.url').startswith('sqlite:'),
|
||||||
**current_app.extensions['migrate'].configure_args)
|
**current_app.extensions['migrate'].configure_args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -33,8 +33,9 @@ def update_data():
|
|||||||
)
|
)
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# change column data type
|
with op.batch_alter_table('setting') as batch_op:
|
||||||
op.alter_column('setting', 'value', existing_type=sa.String(256), type_=sa.Text())
|
# change column data type
|
||||||
|
batch_op.alter_column('value', existing_type=sa.String(256), type_=sa.Text())
|
||||||
# update data for new schema
|
# update data for new schema
|
||||||
update_data()
|
update_data()
|
||||||
|
|
||||||
@ -42,5 +43,6 @@ def upgrade():
|
|||||||
def downgrade():
|
def downgrade():
|
||||||
# delete added records in previous version
|
# delete added records in previous version
|
||||||
op.execute("DELETE FROM setting WHERE id > 41")
|
op.execute("DELETE FROM setting WHERE id > 41")
|
||||||
# change column data type
|
with op.batch_alter_table('setting') as batch_op:
|
||||||
op.alter_column('setting', 'value', existing_type=sa.Text(), type_=sa.String(256))
|
# change column data type
|
||||||
|
batch_op.alter_column('value', existing_type=sa.Text(), type_=sa.String(256))
|
||||||
|
@ -23,8 +23,10 @@ def upgrade():
|
|||||||
# written to the DB.
|
# written to the DB.
|
||||||
op.execute("DELETE FROM setting")
|
op.execute("DELETE FROM setting")
|
||||||
|
|
||||||
# drop view column since we don't need it
|
with op.batch_alter_table('setting') as batch_op:
|
||||||
op.drop_column('setting', 'view')
|
# drop view column since we don't need it
|
||||||
|
batch_op.drop_column('view')
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.add_column('setting', sa.Column('view', sa.String(length=64), nullable=True))
|
with op.batch_alter_table('setting') as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('view', sa.String(length=64), nullable=True))
|
||||||
|
Loading…
Reference in New Issue
Block a user