Skip to content

Commit

Permalink
Remove all topic.tag_ids from database (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-peschke authored Sep 13, 2023
1 parent 1ad1192 commit 04e9eed
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion global/data/example-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 46,
"_migration_index": 47,
"organization": {
"1": {
"id": 1,
Expand Down
2 changes: 1 addition & 1 deletion global/data/initial-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 46,
"_migration_index": 47,
"organization": {
"1": {
"id": 1,
Expand Down
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 tests/system/migrations/test_0046_fix_topic_tag_ids_error.py
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",
},
)

0 comments on commit 04e9eed

Please sign in to comment.