Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def init(
file_path,
toml_path,
script_location=toml_script_location_directory,
append_delimiter=b"\n\n",
)
else:
script._generate_template(
Expand Down
7 changes: 7 additions & 0 deletions alembic/util/pyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def template_to_file(
output_encoding: str,
*,
append: bool = False,
append_delimiter: Optional[bytes] = None,
**kw: Any,
) -> None:
template = Template(filename=_preserving_path_as_str(template_file))
Expand All @@ -45,6 +46,12 @@ def template_to_file(
"template-oriented traceback." % fname
)
else:
if append and append_delimiter:
if os.path.exists(dest):
with open(dest, "rb") as f:
_exsiting = f.read()
if not _exsiting.endswith(append_delimiter):
output = append_delimiter + output
with open(dest, "ab" if append else "wb") as f:
f.write(output)

Expand Down