Skip to content

Commit

Permalink
add cleanup of temp dump files (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
oruehenbeck authored Jun 19, 2024
1 parent 6556254 commit 019283d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions django_migrations_ci/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,13 @@ def dump(connection, output_file, storage, *, verbosity=1):
backend = _get_db_backend(connection)

# Dump to a temp file because backends expect a filename instead of a file object.
_, tmp_filename = tempfile.mkstemp(prefix="migrateci", suffix=".sql")
backend.dump(connection, tmp_filename)

# Copy it to the storage.
with (
open(tmp_filename) as tmp_fp,
storage.open(output_file, "w") as output_fp,
):
output_fp.write(tmp_fp.read())
with tempfile.NamedTemporaryFile(prefix="migrateci", suffix=".sql") as tmp_sql_fp:
backend.dump(connection, tmp_sql_fp.name)
tmp_sql_fp.flush()

# Copy it to the storage.
with open(tmp_sql_fp.name, "r") as input_fp, storage.open(output_file, "w") as output_fp:
output_fp.write(input_fp.read())


def hash_files(depth=0):
Expand Down

0 comments on commit 019283d

Please sign in to comment.