added option to generate empty migration file

This commit is contained in:
ar0ne
2023-12-26 22:55:51 +05:30
parent 01264f3f27
commit b1ff2418f5
3 changed files with 24 additions and 5 deletions

View File

@@ -123,8 +123,8 @@ class Command:
inspect = cls(connection, tables)
return await inspect.inspect()
async def migrate(self, name: str = "update"):
return await Migrate.migrate(name)
async def migrate(self, name: str = "update", empty: bool = False) -> str:
return await Migrate.migrate(name, empty)
async def init_db(self, safe: bool):
location = self.location

View File

@@ -130,12 +130,16 @@ class Migrate:
return version
@classmethod
async def migrate(cls, name) -> str:
async def migrate(cls, name: str, empty: bool) -> str:
"""
diff old models and new models to generate diff content
:param name:
:param name: str name for migration
:param empty: bool if True generates empty migration
:return:
"""
if empty:
return await cls._generate_diff_py(name)
new_version_content = get_models_describe(cls.app)
cls.diff_models(cls._last_version_content, new_version_content)
cls.diff_models(new_version_content, cls._last_version_content, False)