Skip to content

Commit

Permalink
Merge branch 'v2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
HadronCollider committed Sep 23, 2021
2 parents 7389d00 + f79e0fd commit 6fbf11c
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions db_versioning/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class Version:
@classmethod
def update_database(cls, collections, prev_version):
"""
<collections> must contains (objects from pymongo)
<collections> must contains (objects from pymongo)
- users
- presentations
- checks
"""
raise NotImplementedError()

@classmethod
def to_dict(cls):
return dict(
Expand All @@ -27,7 +27,7 @@ def get_version(version_name):
for version in VERSIONS:
if version.version == version_name:
return version
return None
return None


class Version10(Version):
Expand Down Expand Up @@ -69,7 +69,7 @@ class Version20(Version):
@classmethod
def update_database(cls, collections, prev_version):
if prev_version in (Version10.VERSION_NAME, Version11.VERSION_NAME):
# process all checks of pres and set filename + user
# process all checks of pres and set filename + user
for presentation in collections['presentations'].find({}):
filename = presentation['name']
user_doc = collections['users'].find_one({'presentations': presentation['_id'] })
Expand All @@ -79,7 +79,7 @@ def update_database(cls, collections, prev_version):
{"_id": check_id},
{ '$set': { 'filename': filename, 'user': user } }
)

# if we have checks without presentation == after prev loop it doesn't include filename/user field
# set default user='moevm', filename='_.pptx'
collections['checks'].update(
Expand Down Expand Up @@ -126,14 +126,43 @@ def update_database(cls, collections, prev_version):
else:
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')

class Version21(Version):
VERSION_NAME = '2.1'
CHANGES = '0/1 -> T/F; criteria.slides_number: [] -> {}'

@classmethod
def update_database(cls, collections, prev_version):
if prev_version in (Version10.VERSION_NAME, Version11.VERSION_NAME, Version20.VERSION_NAME):

#mv from 0/-1 -> T/F
for check in collections['checks'].find({}):
check_dt = Checks(check).get_checks().items()
upd_check = {k: False if v == -1 else v for k, v in check_dt}
collections['checks'].update(
{'_id': check['_id']},
{'$set': upd_check}
)

for user in collections['users'].find():
criteria_dt = Checks(user['criteria']).get_checks()
upd_criteria = {k: False if v == -1 else True for k, v in criteria_dt.items()}
upd_criteria['slides_number'] = {"sld_num": criteria_dt['slides_number'], "detect_additional": True} if upd_criteria['slides_number'] else False
collections['users'].update(
{'_id': user['_id']},
{'$set': {'criteria': upd_criteria}}
)

else:
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')

VERSIONS = {
'1.0': Version10,
'1.1': Version11,
'2.0': Version20,
'2.1': Version21,
}
LAST_VERSION = '2.0'
LAST_VERSION = '2.1'


for _, ver in VERSIONS.items():
print(ver.to_dict())
print(ver.to_dict())

0 comments on commit 6fbf11c

Please sign in to comment.