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))
|
||||
|
||||
version_file = Path(cls.migrate_location, version)
|
||||
content = MIGRATE_TEMPLATE.format(
|
||||
upgrade_sql=";\n ".join(cls.upgrade_operators) + ";",
|
||||
downgrade_sql=";\n ".join(cls.downgrade_operators) + ";",
|
||||
)
|
||||
content = cls._get_diff_file_content()
|
||||
|
||||
with open(version_file, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
@ -151,6 +148,21 @@ class Migrate:
|
||||
|
||||
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
|
||||
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:
|
||||
mocker.patch("os.listdir", return_value=[])
|
||||
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:
|
||||
Migrate.migrate_location = temp_dir
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user