Created
April 14, 2011 21:33
-
-
Save mccutchen/920610 to your computer and use it in GitHub Desktop.
Map-reduce task to clean up App Engine datastore entities whose models have changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mapreduce import operation as op | |
def scrubber(entity): | |
"""Deletes any data from the underlying datastore that are no longer | |
present in the entity's model definition. | |
""" | |
# What properties are still defined on the model? | |
valid_props = set(entity.properties().keys()) | |
# What properties are attached in the datastore? | |
raw_props = set(entity._entity.keys()) | |
# We need to delete those that are in raw_props but not valid_props | |
to_delete = raw_props - valid_props | |
if to_delete: | |
for field in to_delete: | |
del entity._entity[field] | |
yield op.db.Put(entity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment