-
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.
Remove all topic.tag_ids from database (#1901)
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 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": 46, | ||
"_migration_index": 47, | ||
"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": 46, | ||
"_migration_index": 47, | ||
"organization": { | ||
"1": { | ||
"id": 1, | ||
|
27 changes: 27 additions & 0 deletions
27
openslides_backend/migrations/migrations/0046_fix_topic_tag_ids_error.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,27 @@ | ||
from typing import Any, Dict, List, Optional | ||
|
||
from datastore.migrations import BaseModelMigration | ||
from datastore.writer.core import BaseRequestEvent, RequestUpdateEvent | ||
|
||
from openslides_backend.shared.patterns import fqid_from_collection_and_id | ||
|
||
|
||
class Migration(BaseModelMigration): | ||
""" | ||
Remove all topic.tag_ids from database | ||
""" | ||
|
||
target_migration_index = 47 | ||
|
||
field = "tag_ids" | ||
|
||
def migrate_models(self) -> Optional[List[BaseRequestEvent]]: | ||
events: List[BaseRequestEvent] = [] | ||
db_models = self.reader.get_all("topic") | ||
for id, model in db_models.items(): | ||
if self.field in model: | ||
update: Dict[str, Any] = {self.field: None} | ||
events.append( | ||
RequestUpdateEvent(fqid_from_collection_and_id("topic", id), update) | ||
) | ||
return events |
17 changes: 17 additions & 0 deletions
17
tests/system/migrations/test_0046_fix_topic_tag_ids_error.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,17 @@ | ||
def test_migration(write, finalize, assert_model): | ||
write( | ||
{ | ||
"type": "create", | ||
"fqid": "topic/61", | ||
"fields": {"id": 61, "tag_ids": [], "title": "topic61 with empty tag ids"}, | ||
}, | ||
) | ||
finalize("0046_fix_topic_tag_ids_error") | ||
|
||
assert_model( | ||
"topic/61", | ||
{ | ||
"id": 61, | ||
"title": "topic61 with empty tag ids", | ||
}, | ||
) |