or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

bulk-operations.mdcustom-types.mddocuments.mdevents-actions.mdfields-types.mdindex.mdinitialization.mdmigrations.mdquery-operations.mdtime-series.md

migrations.mddocs/

0

# Migrations

1

2

Schema migration tools for iterative and free-form data migrations with batch processing support.

3

4

## Capabilities

5

6

### Iterative Migration

7

8

```python { .api }

9

def iterative_migration(

10

document_models: List[Type[Document]],

11

batch_size: int = 1000

12

):

13

"""Decorator for creating iterative data migrations with batching."""

14

...

15

```

16

17

### Free Fall Migration

18

19

```python { .api }

20

def free_fall_migration(document_models: List[Type[Document]]):

21

"""Decorator for creating free-form migration functions."""

22

...

23

```

24

25

## Usage Examples

26

27

```python

28

from beanie import Document, iterative_migration, free_fall_migration

29

30

class User(Document):

31

name: str

32

email: str

33

34

class Settings:

35

collection = "users"

36

37

@iterative_migration(document_models=[User], batch_size=100)

38

async def migrate_user_data():

39

"""Add default values for new field."""

40

async for user in User.find({"active": {"$exists": False}}):

41

user.active = True

42

await user.save()

43

44

@free_fall_migration(document_models=[User])

45

async def complex_migration():

46

"""Complex data transformation."""

47

# Custom migration logic

48

await User.find({"old_field": {"$exists": True}}).update({"$unset": {"old_field": ""}})

49

```