Skip to content

Commit

Permalink
Use persistent IDs when creating derived events (#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra authored Nov 1, 2024
1 parent 2fb52be commit 3612f81
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion betty/deriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from enum import Enum
from typing import Iterable, cast
from uuid import uuid5, NAMESPACE_URL

from betty.locale import DateRange, Date, Localizer
from betty.model.ancestry import Person, Presence, Event, Subject, Ancestry
Expand All @@ -32,6 +33,15 @@ class Derivation(Enum):
UPDATE = 3


def _derive_event_id(derivable_event_type: type[EventType], person: Person) -> str:
return str(
uuid5(
NAMESPACE_URL,
f"betty-deriver://{derivable_event_type.name()}/{person.id}",
)
)


class Deriver:
"""
Derive information from ancestries, and create new entities or update existing ones.
Expand Down Expand Up @@ -111,7 +121,13 @@ def _derive_person(
self._lifetime_threshold,
):
derivable_events = [
(Event(event_type=derivable_event_type), Derivation.CREATE),
(
Event(
id=_derive_event_id(derivable_event_type, person),
event_type=derivable_event_type,
),
Derivation.CREATE,
),
]
else:
return 0, 0
Expand Down

0 comments on commit 3612f81

Please sign in to comment.