Fix database migration script
This commit is contained in:
parent
a7cff4af57
commit
71eb6bf04b
1 changed files with 22 additions and 6 deletions
|
|
@ -39,18 +39,34 @@ def upgrade():
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
)
|
)
|
||||||
with op.batch_alter_table('task', schema=None) as batch_op:
|
with op.batch_alter_table('task', schema=None) as batch_op:
|
||||||
batch_op.add_column(sa.Column('mental_burn', sa.Integer(), nullable=False, default=0))
|
batch_op.add_column(sa.Column('mental_burn', sa.Integer(), nullable=True, default=0))
|
||||||
batch_op.add_column(sa.Column('social_burn', sa.Integer(), nullable=False, default=0))
|
batch_op.add_column(sa.Column('social_burn', sa.Integer(), nullable=True, default=0))
|
||||||
batch_op.add_column(sa.Column('time_estimate', sa.Integer(), nullable=True))
|
batch_op.add_column(sa.Column('time_estimate', sa.Integer(), nullable=True))
|
||||||
batch_op.add_column(sa.Column('time_spent', sa.Integer(), nullable=False, default=0))
|
batch_op.add_column(sa.Column('time_spent', sa.Integer(), nullable=True, default=0))
|
||||||
batch_op.add_column(sa.Column('importance', sa.Integer(), nullable=False, default=2))
|
batch_op.add_column(sa.Column('importance', sa.Integer(), nullable=True, default=2))
|
||||||
batch_op.add_column(sa.Column('divisible', sa.Boolean(), nullable=False, default=False))
|
batch_op.add_column(sa.Column('divisible', sa.Boolean(), nullable=True, default=False))
|
||||||
batch_op.add_column(sa.Column('last_reviewed', sa.DateTime(), nullable=True))
|
batch_op.add_column(sa.Column('last_reviewed', sa.DateTime(), nullable=True))
|
||||||
|
|
||||||
batch_op.alter_column('due',
|
batch_op.alter_column('due',
|
||||||
existing_type=sa.DATETIME(),
|
existing_type=sa.DATETIME(),
|
||||||
nullable=True)
|
nullable=True)
|
||||||
batch_op.drop_column('soft_due')
|
batch_op.drop_column('soft_due')
|
||||||
|
|
||||||
|
defaults = [
|
||||||
|
('mental_burn', 0),
|
||||||
|
('social_burn', 0),
|
||||||
|
('time_spent' , 0),
|
||||||
|
('importance' , 2),
|
||||||
|
('divisible' , 'false'),
|
||||||
|
]
|
||||||
|
|
||||||
|
for column, val in defaults:
|
||||||
|
op.execute(f'UPDATE task SET {column} = {val}')
|
||||||
|
|
||||||
|
with op.batch_alter_table('task', schema=None) as batch_op:
|
||||||
|
for column, _ in defaults:
|
||||||
|
batch_op.alter_column(column, nullable=False)
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue