-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix meeting.clone set active code (#2110)
* Fix meting.clone set active code * Implement data repair migration * Fix tests
- Loading branch information
1 parent
60c8359
commit d655bba
Showing
6 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"_migration_index": 48, | ||
"_migration_index": 49, | ||
"organization": { | ||
"1": { | ||
"id": 1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"_migration_index": 48, | ||
"_migration_index": 49, | ||
"organization": { | ||
"1": { | ||
"id": 1, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
openslides_backend/migrations/migrations/0048_fix_broken_meeting_clones.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import List, Optional | ||
|
||
from datastore.migrations import BaseModelMigration | ||
from datastore.shared.util import fqid_from_collection_and_id | ||
from datastore.writer.core import BaseRequestEvent, RequestUpdateEvent | ||
|
||
|
||
class Migration(BaseModelMigration): | ||
""" | ||
This migration finds and fixes broken relations created by the fact that, up unil now, | ||
meeting.clone could create meetings that were active and archived at the same time. | ||
""" | ||
|
||
target_migration_index = 49 | ||
fields = ["set_workflow_timestamp", "allow_motion_forwarding"] | ||
|
||
def migrate_models(self) -> Optional[List[BaseRequestEvent]]: | ||
events: List[BaseRequestEvent] = [] | ||
db_models = self.reader.get_all("meeting") | ||
archived_ids: List[int] = [] | ||
active_ids: List[int] = [] | ||
for id, model in db_models.items(): | ||
if model.get("is_archived_in_organization_id"): | ||
if model.get("is_active_in_organization_id"): | ||
events.append( | ||
RequestUpdateEvent( | ||
fqid_from_collection_and_id("meeting", id), | ||
{"is_archived_in_organization_id": None}, | ||
) | ||
) | ||
active_ids.append(id) | ||
else: | ||
archived_ids.append(id) | ||
else: | ||
active_ids.append(id) | ||
events.append( | ||
RequestUpdateEvent( | ||
fqid_from_collection_and_id("organization", 1), | ||
{ | ||
"active_meeting_ids": active_ids, | ||
"archived_meeting_ids": archived_ids, | ||
}, | ||
) | ||
) | ||
return events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
tests/system/migrations/test_0048_fix_broken_meeting_clones.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
def test_migration(write, finalize, assert_model): | ||
write( | ||
{ | ||
"type": "create", | ||
"fqid": "organization/1", | ||
"fields": { | ||
"id": 1, | ||
"archived_meeting_ids": [101], | ||
"active_meeting_ids": [100, 102], | ||
"committee_ids": [10], | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "committee/10", | ||
"fields": { | ||
"id": 10, | ||
"organization_id": 1, | ||
"meeting_ids": [100, 101, 102, 103], | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "meeting/100", | ||
"fields": { | ||
"id": 100, | ||
"name": "Active", | ||
"committee_id": 10, | ||
"is_active_in_organization_id": 1, | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "meeting/101", | ||
"fields": { | ||
"id": 101, | ||
"name": "Archived", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "meeting/102", | ||
"fields": { | ||
"id": 102, | ||
"name": "Copy of archived", | ||
"committee_id": 10, | ||
"is_active_in_organization_id": 1, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "meeting/103", | ||
"fields": { | ||
"id": 103, | ||
"name": "Archived copy of archived", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
}, | ||
{ | ||
"type": "create", | ||
"fqid": "meeting/104", | ||
"fields": { | ||
"id": 104, | ||
"name": "Archived copy of archived2", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
}, | ||
) | ||
write({"type": "delete", "fqid": "meeting/104"}) | ||
|
||
finalize("0048_fix_broken_meeting_clones") | ||
|
||
assert_model( | ||
"organization/1", | ||
{ | ||
"id": 1, | ||
"committee_ids": [10], | ||
"active_meeting_ids": [100, 102], | ||
"archived_meeting_ids": [101, 103], | ||
}, | ||
) | ||
assert_model( | ||
"meeting/100", | ||
{ | ||
"id": 100, | ||
"name": "Active", | ||
"committee_id": 10, | ||
"is_active_in_organization_id": 1, | ||
}, | ||
) | ||
assert_model( | ||
"meeting/101", | ||
{ | ||
"id": 101, | ||
"name": "Archived", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
) | ||
assert_model( | ||
"meeting/102", | ||
{ | ||
"id": 102, | ||
"name": "Copy of archived", | ||
"committee_id": 10, | ||
"is_active_in_organization_id": 1, | ||
}, | ||
) | ||
assert_model( | ||
"meeting/103", | ||
{ | ||
"id": 103, | ||
"name": "Archived copy of archived", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
}, | ||
) | ||
assert_model( | ||
"meeting/104", | ||
{ | ||
"id": 104, | ||
"name": "Archived copy of archived2", | ||
"committee_id": 10, | ||
"is_archived_in_organization_id": 1, | ||
"meta_deleted": True, | ||
}, | ||
) |