-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20250819210945_re2_pings.py
More file actions
51 lines (38 loc) · 1.06 KB
/
20250819210945_re2_pings.py
File metadata and controls
51 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import Annotated
from beanie import Document, Indexed, iterative_migration
from pydantic import BaseModel
class PhrasePing(BaseModel):
phrase: str
is_re2: bool
class NewPing(Document):
user_id: Annotated[int, Indexed()]
pings: list[PhrasePing]
dnd: bool
class Settings:
name = "pings"
class OldPing(Document):
user_id: Annotated[int, Indexed()]
word_pings: list[str]
dnd: bool
class Settings:
name = "pings"
class Forward:
@iterative_migration()
async def str_to_word_ping_model(
self,
input_document: OldPing,
output_document: NewPing,
):
output_document.pings = [
PhrasePing(phrase=word, is_re2=False) for word in input_document.word_pings
]
class Backward:
@iterative_migration()
async def str_to_word_ping_model(
self,
input_document: NewPing,
output_document: OldPing,
):
output_document.word_pings = [
ping.phrase for ping in input_document.pings if not ping.is_re2
]