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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ jobs:
- arrangement: workers
database: Postgres

- arrangement: monolith
database: Psycopg

- arrangement: workers
database: Psycopg

Expand Down
15 changes: 14 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ postgres = [
"psycopg2cffi>=2.8;platform_python_implementation == 'PyPy'",
"psycopg2cffi-compat==1.1;platform_python_implementation == 'PyPy'",
]
psycopg = ["psycopg>=3.1"]
# v3.2.8 was selected here as minimum to support the libpq5 shipped with debian
# bookworm. This libpq5 includes support for postgres 18 and psycopg will fail to build
# below this selected version.
# See: https://github.com/psycopg/psycopg/pull/1084
psycopg = ["psycopg[c]>=3.2.8"]
saml2 = [
"pysaml2>=4.5.0",

Expand Down Expand Up @@ -179,7 +183,7 @@ all = [
"psycopg2cffi>=2.8;platform_python_implementation == 'PyPy'",
"psycopg2cffi-compat==1.1;platform_python_implementation == 'PyPy'",
# experimental psycopg for postgres
"psycopg>=3.1",
"psycopg[c]>=3.2.8",
# saml2
"pysaml2>=4.5.0",
# oidc and jwt
Expand Down
15 changes: 10 additions & 5 deletions scripts-dev/complement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ main() {
echo_if_github "::endgroup::"

fi

echo "Docker images built."
else
echo "Skipping Docker image build as requested."
Expand Down Expand Up @@ -271,8 +271,12 @@ main() {
export PASS_SYNAPSE_WORKER_TYPES="$WORKER_TYPES"

# Workers can only use Postgres as a database.
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres

# A handy pattern for lower-casing all letters in a variable, `${variable,,}`
if [[ "${POSTGRES,,}" = "psycopg" ]]; then
export PASS_SYNAPSE_COMPLEMENT_DATABASE=psycopg
else
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
fi
# And provide some more configuration to complement.

# It can take quite a while to spin up a worker-mode Synapse for the first
Expand All @@ -281,7 +285,8 @@ main() {
export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120
else
export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=
if [[ "$POSTGRES" = "psycopg" ]]; then
# A handy pattern for lower-casing all letters in a variable, `${variable,,}`
if [[ "${POSTGRES,,}" = "psycopg" ]]; then
export PASS_SYNAPSE_COMPLEMENT_DATABASE=psycopg
elif [[ -n "$POSTGRES" ]]; then
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
Expand Down Expand Up @@ -319,7 +324,7 @@ main() {
echo "Skipping Complement run as requested."
return 0
fi

# Run the tests!
echo "Running Complement with ${test_args[@]} $@ ${test_packages[@]}"
cd "$COMPLEMENT_DIR"
Expand Down
7 changes: 7 additions & 0 deletions synapse/storage/engines/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class PostgresEngine(
BaseDatabaseEngine[ConnectionType, CursorType, IsolationLevelType],
metaclass=abc.ABCMeta,
):
"""
An Abstract Base Class for use by Postgres connection libraries.
Currently supported:
* Psycopg2 -> `Psycopg2Engine`
* Psycopg -> `PsycopgEngine`
"""

isolation_level_map: Mapping[IsolationLevel, IsolationLevelType]
default_isolation_level: IsolationLevelType

Expand Down
8 changes: 8 additions & 0 deletions synapse/storage/engines/psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class PsycopgEngine(
psycopg.Connection[tuple], psycopg.Cursor[tuple], psycopg.IsolationLevel # type: ignore[type-var]
]
):
"""
The class that defines how Synapse will interact with Postgres using the psycopg
version 3+ module.

NOTE: While psycopg does allow for return types other than tuples, for now that is
forced in order to match with existing psycopg2 behavior.
"""

def __init__(self, database_config: Mapping[str, Any]):
super().__init__(psycopg, database_config) # type: ignore[arg-type]
# psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
Expand Down
6 changes: 6 additions & 0 deletions synapse/storage/engines/psycopg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
class Psycopg2Engine(
PostgresEngine[psycopg2.extensions.connection, psycopg2.extensions.cursor, int]
):
"""
The class that defines how Synapse will interact with Postgres using the psycopg
version 2.x module.

"""

def __init__(self, database_config: Mapping[str, Any]):
super().__init__(psycopg2, database_config)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
Expand Down
Loading