Added failure handling for bussy databases

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-03 12:09:44 +02:00
parent 7d3f0a3ae3
commit 3ed89a59a8
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E

View File

@ -44,14 +44,18 @@ def main():
sys.exit(1) sys.exit(1)
for sqlfile in sql_files: for sqlfile in sql_files:
dbname = os.path.splitext(os.path.basename(sqlfile))[0] # Extract database name by stripping the full suffix '.backup.sql'
filename = os.path.basename(sqlfile)
if not filename.endswith('.backup.sql'):
continue
dbname = filename[:-len('.backup.sql')]
print(f"=== Processing {sqlfile} → database: {dbname} ===") print(f"=== Processing {sqlfile} → database: {dbname} ===")
# Drop the database if it already exists # Drop the database, forcing disconnect of sessions if necessary
run_command([ run_command([
"docker", "exec", "-i", container, "docker", "exec", "-i", container,
"psql", "-U", "postgres", "-c", "psql", "-U", "postgres", "-c",
f"DROP DATABASE IF EXISTS \"{dbname}\";" f"DROP DATABASE IF EXISTS \"{dbname}\" WITH (FORCE);"
]) ])
# Create a fresh database # Create a fresh database