Create NestedMutableList/JSON Alembic Migration

A commented out portion was added for a simpler add/drop column style.
https://blog.miguelgrinberg.com/post/fixing-alter-table-errors-with-flask-migrate-and-sqlite
This commit is contained in:
Xevion
2021-02-17 04:57:30 -06:00
parent 8d8fe83b5f
commit 20566242ae

View File

@@ -0,0 +1,38 @@
"""Change votes to nested mutable list (JSON backed)
Revision ID: b26551e73407
Revises: 43c1baca42a2
Create Date: 2021-02-17 04:40:19.691104-06:00
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
from sqlalchemy_json import NestedMutableList
revision = 'b26551e73407'
down_revision = '43c1baca42a2'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
with op.batch_alter_table('submission', schema=None) as batch_op:
batch_op.alter_column("votes", type_=NestedMutableList.as_mutable(sa.JSON))
# batch_op.drop_column('submission', 'votes')
# batch_op.add_column('submission', sa.Column('votes', NestedMutableList.as_mutable(sa.JSON)))
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
with op.batch_alter_table('submission', schema=None) as batch_op:
batch_op.alter_column("votes", type_=sa.Integer(), nullable=True)
# batch_op.drop_column('votes')
# batch_op.add_column('submission', sa.Column('votes', sa.Integer(), nullable=True))