ohmyapi 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ohmyapi
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: A Django-like but async web-framework based on FastAPI and TortoiseORM.
5
5
  License-Expression: MIT
6
6
  Keywords: fastapi,tortoise,orm,async,web-framework
@@ -13,11 +13,10 @@ ohmyapi/core/templates/app/routes.py.j2,sha256=Ee3xeVdM_G5-TRw14_C6siJTrEXtnRUD5
13
13
  ohmyapi/core/templates/project/pyproject.toml.j2,sha256=rk5baSS-nhW2mbdl60CHoXmeTBkqnzUEMwrRNxUnkt4,250
14
14
  ohmyapi/core/templates/project/settings.py.j2,sha256=RBKGB8MZWPM3Bp0a57Y1YrSvSXxh502TUnJqbbu48Ig,138
15
15
  ohmyapi/db/__init__.py,sha256=p5oXqYUKT6eAoE-9JD-p6zKo9s-H84rJbrKxFna8Kvc,63
16
- ohmyapi/db/migration_manager.py,sha256=dTabeDyd6ZIa0lORlKRuiLnBTcsVAgUjgrO9_bew6pQ,3621
17
16
  ohmyapi/db/model/__init__.py,sha256=owKYpx5a2ZFTBgBqyEKN09AvY1cSP0dy1O7d3_sUVgM,33
18
17
  ohmyapi/db/model/model.py,sha256=PSzK_d8IZQExSRuTrEyPnqfa4GENQhbBZsVxxLWTR4g,1570
19
18
  ohmyapi/router.py,sha256=RzDXrtJJrk4eWdt9qoKBfz6g0S5WZq2hDQoFy5whR6A,40
20
- ohmyapi-0.1.5.dist-info/METADATA,sha256=nkA_r4KK7onicJf7oQKsP3kjtU0T29JlTLdbbknde08,4268
21
- ohmyapi-0.1.5.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
22
- ohmyapi-0.1.5.dist-info/entry_points.txt,sha256=ZCZJLw_ojguyr1WOmb8UwHrr42hiLj6-Kzh4mMa_7Ns,44
23
- ohmyapi-0.1.5.dist-info/RECORD,,
19
+ ohmyapi-0.1.6.dist-info/METADATA,sha256=aLe3O1xcYRb-a_WG6w4QkWxneATuaHjdmWZezxBcxhw,4268
20
+ ohmyapi-0.1.6.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
21
+ ohmyapi-0.1.6.dist-info/entry_points.txt,sha256=ZCZJLw_ojguyr1WOmb8UwHrr42hiLj6-Kzh4mMa_7Ns,44
22
+ ohmyapi-0.1.6.dist-info/RECORD,,
@@ -1,90 +0,0 @@
1
- import asyncio
2
- from pathlib import Path
3
- from aerich import Command
4
- from ohmyapi.core import runtime
5
-
6
-
7
- class MigrationManager:
8
- def __init__(self, project):
9
- self.project = project
10
- self._commands = {}
11
- # Compute tortoise_config grouped by app module
12
- self._tortoise_config = self._build_tortoise_config()
13
-
14
- def _build_tortoise_config(self) -> dict:
15
- """
16
- Build Tortoise config from the flat model_registry,
17
- grouping models by app module for Aerich compatibility.
18
- """
19
- db_url = self.project.settings.DATABASE_URL
20
- registry = self.project.model_registry # flat: model_path -> class
21
-
22
- apps_modules = {}
23
- for model_path, model_cls in registry.items():
24
- if not isinstance(model_cls, type):
25
- raise TypeError(f"Registry value must be a class, got {type(model_cls)}: {model_cls}")
26
- # Extract app module by removing the model class name
27
- # Example: 'ohmyapi.apps.auth.User' -> 'ohmyapi.apps.auth'
28
- app_module = ".".join(model_path.split(".")[:-1])
29
- apps_modules.setdefault(app_module, []).append(model_cls)
30
-
31
- # Build Tortoise config
32
- apps_config = {}
33
- for app_module, models in apps_modules.items():
34
- modules_set = set(m.__module__ for m in models)
35
- apps_config[app_module] = {
36
- "models": list(modules_set),
37
- "default_connection": "default",
38
- }
39
-
40
- return {
41
- "connections": {"default": db_url},
42
- "apps": apps_config,
43
- }
44
-
45
- def get_apps(self):
46
- """Return app modules extracted from the registry"""
47
- return list(self._tortoise_config["apps"].keys())
48
-
49
- def get_migration_location(self, app_module: str) -> str:
50
- """Return the path to the app's migrations folder"""
51
- try:
52
- module = __import__(app_module, fromlist=["migrations"])
53
- if not hasattr(module, "__file__") or module.__file__ is None:
54
- raise ValueError(f"Cannot determine filesystem path for app '{app_module}'")
55
- app_path = Path(module.__file__).parent
56
- migrations_path = app_path / "migrations"
57
- migrations_path.mkdir(exist_ok=True)
58
- return str(migrations_path)
59
- except ModuleNotFoundError:
60
- raise ValueError(f"App module '{app_module}' cannot be imported")
61
-
62
- async def init_app_command(self, app_module: str) -> Command:
63
- """Initialize Aerich command for a specific app module"""
64
- location = self.get_migration_location(app_module)
65
- cmd = Command(
66
- tortoise_config=self._tortoise_config,
67
- app=app_module,
68
- location=location,
69
- )
70
- await cmd.init()
71
- self._commands[app_module] = cmd
72
- return cmd
73
-
74
- async def makemigrations(self, app_module: str):
75
- """Generate migrations for a specific app"""
76
- cmd = self._commands.get(app_module) or await self.init_app_command(app_module)
77
- await cmd.migrate()
78
-
79
- async def migrate(self, app_module: str = None):
80
- """Apply migrations. If app_module is None, migrate all apps"""
81
- apps_to_migrate = [app_module] if app_module else self.get_apps()
82
- for app in apps_to_migrate:
83
- cmd = self._commands.get(app) or await self.init_app_command(app)
84
- await cmd.upgrade()
85
-
86
- async def show_migrations(self, app_module: str):
87
- """List migrations for an app"""
88
- cmd = self._commands.get(app_module) or await self.init_app_command(app_module)
89
- await cmd.history()
90
-