Skip to content

Commit

Permalink
Try to find annotation before importing as a new one
Browse files Browse the repository at this point in the history
We sort annotations that we want to import in descending `updated` order.
Which means that when we import annotation X on the first run, and this
annotation gets updated before the second run, we will have to try and
find annotations, and on success update annotation X instead of creating
a new one which would lead to a unique constraint error on the `id`
column.

This use case needs to be handled as we want to run the migration
multiple times to ensure we have all the new and updated annotations
correctly migrated to Postgres.
  • Loading branch information
chdorner committed Feb 19, 2016
1 parent 9ce594c commit b504d31
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ def annotation_from_data(id, data):
if id == '_query':
raise Skip("not an annotation (id=_query)")

ann = Annotation(id=id)
ann = Annotation.query.get(id)
if ann is None:
ann = Annotation(id=id)

ann.created = dateparser.parse(data.pop('created')).replace(tzinfo=None)
ann.updated = dateparser.parse(data.pop('updated')).replace(tzinfo=None)
ann.userid = data.pop('user')
Expand Down

0 comments on commit b504d31

Please sign in to comment.