remove redundant comma for empty migration
This commit is contained in:
parent
b1ff2418f5
commit
ad54b5e9dd
@ -120,10 +120,7 @@ class Migrate:
|
|||||||
os.unlink(Path(cls.migrate_location, version_file))
|
os.unlink(Path(cls.migrate_location, version_file))
|
||||||
|
|
||||||
version_file = Path(cls.migrate_location, version)
|
version_file = Path(cls.migrate_location, version)
|
||||||
content = MIGRATE_TEMPLATE.format(
|
content = cls._get_diff_file_content()
|
||||||
upgrade_sql=";\n ".join(cls.upgrade_operators) + ";",
|
|
||||||
downgrade_sql=";\n ".join(cls.downgrade_operators) + ";",
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(version_file, "w", encoding="utf-8") as f:
|
with open(version_file, "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
@ -151,6 +148,21 @@ class Migrate:
|
|||||||
|
|
||||||
return await cls._generate_diff_py(name)
|
return await cls._generate_diff_py(name)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_diff_file_content(cls) -> str:
|
||||||
|
"""
|
||||||
|
builds content for diff file from template
|
||||||
|
"""
|
||||||
|
def join_lines(lines: List[str]) -> str:
|
||||||
|
if not lines:
|
||||||
|
return ""
|
||||||
|
return ";\n ".join(lines) + ";"
|
||||||
|
|
||||||
|
return MIGRATE_TEMPLATE.format(
|
||||||
|
upgrade_sql=join_lines(cls.upgrade_operators),
|
||||||
|
downgrade_sql=join_lines(cls.downgrade_operators)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _add_operator(cls, operator: str, upgrade=True, fk_m2m_index=False):
|
def _add_operator(cls, operator: str, upgrade=True, fk_m2m_index=False):
|
||||||
"""
|
"""
|
||||||
|
@ -973,7 +973,7 @@ def test_sort_all_version_files(mocker):
|
|||||||
async def test_empty_migration(mocker) -> None:
|
async def test_empty_migration(mocker) -> None:
|
||||||
mocker.patch("os.listdir", return_value=[])
|
mocker.patch("os.listdir", return_value=[])
|
||||||
Migrate.app = "foo"
|
Migrate.app = "foo"
|
||||||
expected_content = MIGRATE_TEMPLATE.format(upgrade_sql=";", downgrade_sql=";")
|
expected_content = MIGRATE_TEMPLATE.format(upgrade_sql="", downgrade_sql="")
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
Migrate.migrate_location = temp_dir
|
Migrate.migrate_location = temp_dir
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user