add snapshot.active in model and migration file

This commit is contained in:
Cayo Puigdefabregas 2022-12-22 18:04:34 +01:00
parent 62de2126c7
commit bf5c3d6abc
2 changed files with 14 additions and 1 deletions

View File

@ -36,7 +36,11 @@ def upgrade_data():
continue continue
dev_id = d.id dev_id = d.id
chid = hashlib.sha3_256(d.hid.encode('utf-8')).hexdigest() chid = hashlib.sha3_256(d.hid.encode('utf-8')).hexdigest()
sql = f"update {get_inv()}.device set chid={chid} where id={dev_id};" sql = f"update {get_inv()}.device set chid='{chid}' where id={dev_id};"
con.execute(sql)
sql = f"update {get_inv()}.snapshot set active=true;"
con.execute(sql)
def upgrade(): def upgrade():
@ -52,11 +56,19 @@ def upgrade():
schema=f'{get_inv()}', schema=f'{get_inv()}',
) )
op.add_column(
'snapshot',
sa.Column('active', sa.Boolean(), default=True, nullable=True),
schema=f'{get_inv()}',
)
upgrade_data() upgrade_data()
op.alter_column('computer', 'user_trusts', nullable=False, schema=f'{get_inv()}') op.alter_column('computer', 'user_trusts', nullable=False, schema=f'{get_inv()}')
op.alter_column('snapshot', 'active', nullable=False, schema=f'{get_inv()}')
def downgrade(): def downgrade():
op.drop_column('computer', 'user_trusts', schema=f'{get_inv()}') op.drop_column('computer', 'user_trusts', schema=f'{get_inv()}')
op.drop_column('device', 'chid', schema=f'{get_inv()}') op.drop_column('device', 'chid', schema=f'{get_inv()}')
op.drop_column('snapshot', 'active', schema=f'{get_inv()}')

View File

@ -678,6 +678,7 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice):
sid = Column(CIText(), nullable=True) sid = Column(CIText(), nullable=True)
settings_version = Column(CIText(), nullable=True) settings_version = Column(CIText(), nullable=True)
is_server_erase = Column(Boolean(), nullable=True) is_server_erase = Column(Boolean(), nullable=True)
active = Column(Boolean(), nullable=True)
def get_last_lifetimes(self): def get_last_lifetimes(self):
"""We get the lifetime and serial_number of the first disk""" """We get the lifetime and serial_number of the first disk"""