Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ def pg_dump_file(out_path: Path):

def pg_restore_file(sql_path: Path):
env = _pg_env()
cmd = ["psql", env["PGDBNAME"]]
# Drop existing objects to ensure the restore can proceed
drop_cmd = ["psql", env["PGDBNAME"], "-c", "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"]
subprocess.run(drop_cmd, check=True, env=env)

cmd = ["psql", env["PGDBNAME"], "-v", "ON_ERROR_STOP=1"]

with open(sql_path, "r") as fh:
subprocess.run(cmd, stdin=fh, check=True, env=env)

Expand Down
3 changes: 2 additions & 1 deletion templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ <h3>Database Backups</h3>
<tr>
<td>{{ b }}</td>
<td>
<form method="post" action="/db_restore">
<form method="post" action="/db_restore" onsubmit="return confirm('Restore from {{ b }}? This will overwrite the current database.');">

<input type="hidden" name="filename" value="{{ b }}">
<button type="submit">Restore</button>
</form>
Expand Down
Loading