Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. from mongodb_migrations.base import BaseMigration
  2.  
  3.  
  4. class Migration(BaseMigration):
  5.  
  6. def upgrade(self):
  7. for doc in self.db['application_rules'].find({'redundancy_level': {'$exists': True}}):
  8. self.db['application_rules'].update(
  9. {'_id': doc['_id']},
  10. {'$unset': {'redundancy_level': 1},
  11. '$set': {
  12. "hosts_settings.redundancy_level": doc['redundancy_level'],
  13. "hubs_settings.redundancy_level": doc['redundancy_level'],
  14. }
  15. }
  16. )
  17.  
  18. def downgrade(self):
  19. for doc in self.db['application_rules'].find({'hubs_settings.redundancy_level': {'$exists': True}}):
  20. self.db['application_rules'].update(
  21. {'_id': doc['_id']},
  22. {'$unset': {'hosts_settings': 1, "hubs_settings": 1},
  23. '$set': {
  24. "redundancy_level": doc['hubs_settings']['redundancy_level'],
  25. }
  26. }
  27. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement