Yes, this is the correct way to perform this operation. I would
suggest adding a new property to the model to store the keys and
update your code to use this new property. This will allow you to
continue using your application while you are performing your schema
migration.

For example:

# Old model definition
class MyModel(db.Model):
  links = db.StringListProperty()

# New model definition
class MyModel(db.Model):
  links = db.StringListProperty()
  link_keys = db.ListProperty(db.Key)  # You may also want to set
indexed = False

  def apply_schema_change(self):
    if not links:
      # There is nothing to update
      return
    self.link_keys = [db.Key(str_key) for str_key in self.links]
    self.links = []  # We don't use this anymore, so delete the data


Then you would call the apply_schema_change method after reading the
model in from datastore, ensuring that the data is now in the new
format.

Then I would use the mapper framework to apply the new schema to all
of the entities in your datastore.


On 5 August 2011 10:53, Tim Hoffman <[email protected]> wrote:
> Hi John
> I have a db.ListProperty(db.String) or db.StringListProperty and I have
> stored keys in it, which of course will be in the str(key) form.
> The conversion tools doesn't convert this sort of thing mainly because
> unless there is an additional mechanism for
> describing what this field holds the conversion tools can't know.
> So you would need to something like
> Convert all the strings back to keys
> keys = [db.Key(i) for i in obj.some_list_property]
> then stick them in some property that is defined as db.ListProperty(db.Key)
> Now the trick will be working out the order of events and possibly
> performing multiple stages
> so you can get you data converted and make the sites work before and after
> transfer/conversion
> Haven't really worked out the order of events I have to go through.
> Rgds
> Tim
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/8_fgPFgpABAJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>



-- 
Greg Darke

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to