|
17 | 17 |
|
18 | 18 |
|
19 | 19 | def upgrade(): |
20 | | - op.add_column('button', sa.Column('order', sa.Integer(), nullable=False)) |
21 | | - op.add_column('button', sa.Column('link', sa.String(), nullable=False)) |
22 | | - op.add_column('button', sa.Column('type', sa.String(), nullable=False)) |
| 20 | + op.add_column('button', sa.Column('order', sa.Integer(), nullable=True)) |
| 21 | + op.add_column('button', sa.Column('link', sa.String(), nullable=True)) |
| 22 | + op.add_column('button', sa.Column('type', sa.String(), nullable=True)) |
| 23 | + conn = op.get_bind() |
| 24 | + res = conn.execute(sa.text("select id from button")).fetchall() |
| 25 | + for i in range(0, len(res)): |
| 26 | + conn.execute(sa.text(f'UPDATE button set order = {i+1}, link = "a", type = "b", where id={res[i]}')) |
| 27 | + op.alter_column('button', 'order', nullable=False) |
| 28 | + op.alter_column('button', 'link', nullable=False) |
| 29 | + op.alter_column('button', 'type', nullable=False) |
23 | 30 | op.alter_column('button', 'name', existing_type=sa.VARCHAR(), nullable=False) |
24 | 31 | op.alter_column('button', 'category_id', existing_type=sa.INTEGER(), nullable=False) |
25 | 32 | op.alter_column('button', 'icon', existing_type=sa.VARCHAR(), nullable=False) |
26 | | - op.add_column('category', sa.Column('order', sa.Integer(), nullable=False)) |
| 33 | + op.add_column('category', sa.Column('order', sa.Integer(), nullable=True)) |
| 34 | + conn = op.get_bind() |
| 35 | + res = conn.execute(sa.text("select id from category")).fetchall() |
| 36 | + for i in range(0, len(res)): |
| 37 | + conn.execute(sa.text(f'select order from category where category.id={res[i]} update category set order = {i+1}')) |
| 38 | + op.alter_column('category', 'order', nullable=False) |
27 | 39 | op.alter_column('category', 'name', existing_type=sa.VARCHAR(), nullable=False) |
28 | 40 | op.alter_column('category', 'type', existing_type=sa.VARCHAR(), nullable=False) |
| 41 | + op.alter_column('button', 'order', nullable=False) |
29 | 42 |
|
30 | 43 |
|
31 | 44 | def downgrade(): |
|
0 commit comments