| 1 |
from inspect import signature |
| 2 |
from typing import Any |
| 3 |
|
| 4 |
from beanie.migrations.controllers.base import BaseMigrationController |
| 5 |
from beanie.odm.documents import Document |
| 6 |
|
| 7 |
|
| 8 |
def free_fall_migration(document_models: list[type[Document]]): |
| 9 |
class FreeFallMigrationController(BaseMigrationController): |
| 10 |
def __init__(self, function): |
| 11 |
self.function = function |
| 12 |
self.function_signature = signature(function) |
| 13 |
self.document_models = document_models |
| 14 |
|
| 15 |
def __call__(self, *args: Any, **kwargs: Any): |
| 16 |
pass |
| 17 |
|
| 18 |
@property |
| 19 |
def models(self) -> list[type[Document]]: |
| 20 |
return self.document_models |
| 21 |
|
| 22 |
async def run(self, session): |
| 23 |
function_kwargs = {"session": session} |
| 24 |
if "self" in self.function_signature.parameters: |
| 25 |
function_kwargs["self"] = None |
| 26 |
await self.function(**function_kwargs) |
| 27 |
|
| 28 |
return FreeFallMigrationController |