-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_schema.py
58 lines (46 loc) · 1.72 KB
/
update_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import logging
import webapp2
from google.appengine.ext import db
from google.appengine.ext import deferred
from model import CrashReport
from search_model import Search
BATCH_SIZE = 100
class SchemaUpdater(object):
"""
Updates the crash reporter schema. Adds the state on the crash reporter.
"""
@classmethod
def delete_search_indexes(cls):
logging.info("Deleting all entries from Search Indexes.")
Search.delete_all_in_index()
@classmethod
def update(cls, cursor=None):
logging.info('Upgrading schema for Crash Reports (Cursor = %s)' % unicode(cursor))
query = CrashReport.all()
if cursor:
query.with_cursor(cursor)
crash_reports = list()
for crash_report in query.fetch(limit=BATCH_SIZE):
crash_report.version = '2'
crash_report.state = 'unresolved'
crash_reports.append(crash_report)
if crash_reports:
updated = len(crash_reports)
logging.info('Updating %s entities', updated)
# update
db.put(crash_reports)
Search.add_crash_reports(crash_reports)
# schedule next request
deferred.defer(SchemaUpdater.update, cursor=query.cursor())
class RemoveSearchIndexes(webapp2.RequestHandler):
def get(self):
deferred.defer(SchemaUpdater.delete_search_indexes)
message = 'Removing all search indexes started'
logging.info(message)
self.response.out.write(message)
class UpdateSchemaHandler(webapp2.RequestHandler):
def get(self):
deferred.defer(SchemaUpdater.update)
message = 'Schema Updates Started'
logging.info(message)
self.response.out.write(message)