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
|
from pydantic.main import BaseModel
from beanie import Document, iterative_migration
class Tag(BaseModel):
color: str
name: str
class OldNote(Document):
title: str
tag: Tag
class Settings:
name = "notes"
indexes = ["title"]
class Note(Document):
title: str
tag: Tag
class Settings:
name = "notes"
indexes = [
"_id",
]
class Forward:
@iterative_migration()
async def name_to_title(
self, input_document: OldNote, output_document: Note
): ...
class Backward:
@iterative_migration()
async def title_to_name(
self, input_document: Note, output_document: OldNote
): ...
|