Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
fixup: make postgres behaviour consistent with sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Quah committed Jan 27, 2023
1 parent 6716f8c commit bb340f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions synapse/storage/engines/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def executescript(cursor: CursorType, script: str) -> None:
This is not provided by DBAPI2, and so needs engine-specific support.
Some database engines may automatically COMMIT the ongoing transaction before
executing the script in its own transaction. The script transaction is left
open and it is the responsibility of the caller to commit it.
Any ongoing transaction is committed before executing the script in its own
transaction. The script transaction is left open and it is the responsibility of
the caller to commit it.
"""
...

Expand Down
6 changes: 5 additions & 1 deletion synapse/storage/engines/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,9 @@ def executescript(cursor: psycopg2.extensions.cursor, script: str) -> None:
"""Execute a chunk of SQL containing multiple semicolon-delimited statements.
Psycopg2 seems happy to do this in DBAPI2's `execute()` function.
For consistency with SQLite, any ongoing transaction is committed before
executing the script in its own transaction. The script transaction is
left open and it is the responsibility of the caller to commit it.
"""
cursor.execute(script)
cursor.execute(f"COMMIT; BEGIN TRANSACTION; {script}")

0 comments on commit bb340f7

Please sign in to comment.