script for set the owners to components from parent device

This commit is contained in:
Cayo Puigdefabregas 2020-10-30 21:39:03 +01:00
parent 5ac1e8efba
commit ed8522c96a
1 changed files with 11 additions and 0 deletions

11
migration_owners.py Normal file
View File

@ -0,0 +1,11 @@
from ereuse_devicehub.resources.device import models as m
from ereuse_devicehub.db import db
def migrate(app):
with app.app_context():
for c in m.Component.query.filter():
if c.parent_id:
c.owner_id = c.parent.owner.id
db.session.add(c)
db.session.commit()
db.session.flush()