Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ktarasz committed Jul 8, 2016
2 parents 6111c9b + 53985ea commit a041edc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/openprocurement/api/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


LOGGER = logging.getLogger(__name__)
SCHEMA_VERSION = 21
SCHEMA_VERSION = 22
SCHEMA_DOC = 'openprocurement_schema'


Expand Down Expand Up @@ -661,3 +661,24 @@ def from20to21(db):
docs = []
if docs:
db.update(docs)


def from21to22(db):
results = db.iterview('tenders/all', 2 ** 10, include_docs=True)
docs = []
for i in results:
doc = i.doc
changed = False
for a in doc.get("awards", []):
for c in a.get("complaints", []):
if 'dateEscalated' in c and c['type'] == 'claim':
c['type'] = 'complaint'
changed = True
if changed:
doc['dateModified'] = get_now().isoformat()
docs.append(doc)
if len(docs) >= 2 ** 7:
result = db.update(docs)
docs = []
if docs:
db.update(docs)
22 changes: 22 additions & 0 deletions src/openprocurement/api/tests/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,28 @@ def test_migrate_from19to20(self):
migrated_item = self.db.get(_id)
self.assertEqual('/tenders/13fcd78ee62e40dda3a89dc930e5bac9/contracts/3e9b292b2a7540a89797de335bf053ce/documents/ebcb5dd7f7384b0fbfbed2dc4252fa6e?download=10367238a2964ee18513f209d9b6d1d3', migrated_item['contracts'][0]['documents'][0]['url'])

def test_migrate_from21to22(self):
set_db_schema_version(self.db, 21)
data = {
'doc_type': 'Tender',
"awards": [
{
"id": "award_id",
"complaints": [
{
"id": "complaint_id",
"type": "claim",
"dateEscalated": "2016-05-11T15:09:53.751926+03:00"
}
]
}
]
}
_id, _rev = self.db.save(data)
migrate_data(self.db, 22)
migrated_item = self.db.get(_id)
self.assertEqual(migrated_item['awards'][0]['complaints'][0]['type'], 'complaint')


def suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit a041edc

Please sign in to comment.