Merge pull request #325 from eReuse/feature/3598-binding

fix migration only devices without placeholders
This commit is contained in:
cayop 2022-08-03 18:42:55 +02:00 committed by GitHub
commit 5593425c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -52,6 +52,8 @@ def init_app():
def clone_computers(): def clone_computers():
for computer in Computer.query.all(): for computer in Computer.query.all():
if computer.placeholder:
continue
clone_device(computer) clone_device(computer)
@ -200,22 +202,22 @@ def remove_placeholders():
for placeholder in Placeholder.query.all(): for placeholder in Placeholder.query.all():
device = placeholder.device device = placeholder.device
binding = placeholder.binding binding = placeholder.binding
if not device or not binding: if not binding:
continue continue
devices.append(placeholder.device.id) devices.append(placeholder.device.id)
for dev in Device.query.filter(Device.id.in_(devices)): for dev in Device.query.filter(Device.id.in_(devices)):
db.session.delete(dev) db.session.delete(dev)
for placeholder in Placeholder.query.all(): # for placeholder in Placeholder.query.all():
device = placeholder.device # device = placeholder.device
binding = placeholder.binding # binding = placeholder.binding
if not device or not binding: # if not device or not binding:
continue # continue
for plog in PlaceholdersLog.query.filter_by(placeholder=placeholder).all(): # for plog in PlaceholdersLog.query.filter_by(placeholder=placeholder).all():
db.session.delete(plog) # db.session.delete(plog)
db.session.delete(placeholder) # db.session.delete(placeholder)
db.session.commit() db.session.commit()