add backups for the abstract phid and dhid
This commit is contained in:
parent
aee34e4989
commit
f19046b2ef
|
@ -279,6 +279,11 @@ class BindingView(GenericMixin):
|
|||
self.abstract_dhid = self.old_device.devicehub_id
|
||||
self.abstract_phid = self.old_placeholder.phid
|
||||
|
||||
# to do a backup of abstract_dhid and abstract_phid in
|
||||
# workbench device
|
||||
self.abstract_device.dhid_bk = self.abstract_dhid
|
||||
self.abstract_device.phid_bk = self.abstract_phid
|
||||
|
||||
def post(self):
|
||||
for plog in PlaceholdersLog.query.filter_by(
|
||||
placeholder_id=self.old_placeholder.id
|
||||
|
@ -379,6 +384,17 @@ class UnBindingView(GenericMixin):
|
|||
c.binding.device.parent = new_device
|
||||
|
||||
placeholder = Placeholder(device=new_device, binding=device, is_abstract=True)
|
||||
if (
|
||||
device.dhid_bk
|
||||
and not Device.query.filter_by(devicehub_id=device.dhid_bk).first()
|
||||
):
|
||||
new_device.devicehub_id = device.dhid_bk
|
||||
if (
|
||||
device.phid_bk
|
||||
and not Placeholder.query.filter_by(phid=device.phid_bk).first()
|
||||
):
|
||||
placeholder.phid = device.phid_bk
|
||||
|
||||
db.session.add(placeholder)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
"""backup dhid
|
||||
|
||||
Revision ID: 6b0880832b78
|
||||
Revises: d7ea9a3b2da1
|
||||
Create Date: 2022-09-07 12:53:25.827186
|
||||
|
||||
"""
|
||||
import citext
|
||||
import sqlalchemy as sa
|
||||
from alembic import context, op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6b0880832b78'
|
||||
down_revision = 'd7ea9a3b2da1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def get_inv():
|
||||
INV = context.get_x_argument(as_dictionary=True).get('inventory')
|
||||
if not INV:
|
||||
raise ValueError("Inventory value is not specified")
|
||||
return INV
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column(
|
||||
'device',
|
||||
sa.Column('dhid_bk', citext.CIText(), unique=False, nullable=True),
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
op.add_column(
|
||||
'device',
|
||||
sa.Column('phid_bk', citext.CIText(), unique=False, nullable=True),
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('device', 'dhid_bk', schema=f'{get_inv()}')
|
||||
op.drop_column('device', 'phid_bk', schema=f'{get_inv()}')
|
|
@ -173,6 +173,8 @@ class Device(Thing):
|
|||
db.CIText(), nullable=True, unique=True, default=create_code
|
||||
)
|
||||
devicehub_id.comment = "device have a unique code."
|
||||
dhid_bk = db.Column(db.CIText(), nullable=True, unique=False)
|
||||
phid_bk = db.Column(db.CIText(), nullable=True, unique=False)
|
||||
active = db.Column(Boolean, default=True)
|
||||
|
||||
_NON_PHYSICAL_PROPS = {
|
||||
|
|
Reference in New Issue