Skip to content
21 changes: 17 additions & 4 deletions migrations/versions/6a486347af93_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@


def upgrade():
op.add_column('button', sa.Column('order', sa.Integer(), nullable=False))
op.add_column('button', sa.Column('link', sa.String(), nullable=False))
op.add_column('button', sa.Column('type', sa.String(), nullable=False))
op.add_column('button', sa.Column('order', sa.Integer(), nullable=True))
op.add_column('button', sa.Column('link', sa.String(), nullable=True))
op.add_column('button', sa.Column('type', sa.String(), nullable=True))
conn = op.get_bind()
res = conn.execute(sa.text("select id from button")).fetchall()
for i in range(0, len(res)):
conn.execute(sa.text(f'UPDATE button set order = {i+1}, link = "a", type = "b", where id={res[i]}'))
op.alter_column('button', 'order', nullable=False)
op.alter_column('button', 'link', nullable=False)
op.alter_column('button', 'type', nullable=False)
op.alter_column('button', 'name', existing_type=sa.VARCHAR(), nullable=False)
op.alter_column('button', 'category_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('button', 'icon', existing_type=sa.VARCHAR(), nullable=False)
op.add_column('category', sa.Column('order', sa.Integer(), nullable=False))
op.add_column('category', sa.Column('order', sa.Integer(), nullable=True))
conn = op.get_bind()
res = conn.execute(sa.text("select id from category")).fetchall()
for i in range(0, len(res)):
conn.execute(sa.text(f'select order from category where category.id={res[i]} update category set order = {i+1}'))
op.alter_column('category', 'order', nullable=False)
op.alter_column('category', 'name', existing_type=sa.VARCHAR(), nullable=False)
op.alter_column('category', 'type', existing_type=sa.VARCHAR(), nullable=False)
op.alter_column('button', 'order', nullable=False)


def downgrade():
Expand Down