Skip to content

Commit 08ed6ef

Browse files
committed
Some refactoring of logical replication API and formatting
1 parent bc1002f commit 08ed6ef

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

testgres/node.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,9 @@ def get_auth_method(t):
501501

502502
if allow_logical:
503503
if not pg_version_ge('10'):
504-
raise InitNodeException("Logical replication is only "
505-
"available for Postgres 10 and newer")
504+
raise InitNodeException(
505+
"Logical replication is only available for Postgres 10 "
506+
"and newer")
506507
conf.write(u"wal_level = logical\n")
507508

508509
# disable UNIX sockets if asked to
@@ -1022,11 +1023,7 @@ def catchup(self, dbname=None, username=None):
10221023
except Exception as e:
10231024
raise_from(CatchUpException("Failed to catch up", poll_lsn), e)
10241025

1025-
def publish(self,
1026-
name,
1027-
tables=None,
1028-
dbname=None,
1029-
username=None):
1026+
def publish(self, name, **kwargs):
10301027
"""
10311028
Create publication for logical replication
10321029
@@ -1036,25 +1033,26 @@ def publish(self,
10361033
dbname: database name where objects or interest are located
10371034
username: replication username
10381035
"""
1039-
return Publication(name=name, node=self, tables=tables, dbname=dbname,
1040-
username=username)
1036+
return Publication(name=name, node=self, **kwargs)
10411037

1042-
def subscribe(self,
1043-
publication,
1044-
name,
1045-
dbname=None,
1046-
username=None,
1047-
**kwargs):
1038+
def subscribe(self, publication, name, dbname=None, username=None,
1039+
**params):
10481040
"""
10491041
Create subscription for logical replication
10501042
10511043
Args:
1052-
subname: subscription name
1044+
name: subscription name
10531045
publication: publication object obtained from publish()
1054-
1046+
dbname: database name
1047+
username: replication username
1048+
params: subscription parameters (see documentation on `CREATE SUBSCRIPTION
1049+
<https://www.postgresql.org/docs/current/static/sql-createsubscription.html>`_
1050+
for details)
10551051
"""
1052+
# yapf: disable
10561053
return Subscription(name=name, node=self, publication=publication,
1057-
dbname=dbname, username=username, **kwargs)
1054+
dbname=dbname, username=username, **params)
1055+
# yapf: enable
10581056

10591057
def pgbench(self,
10601058
dbname=None,

testgres/pubsub.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self,
106106
publication,
107107
dbname=None,
108108
username=None,
109-
**kwargs):
109+
**params):
110110
"""
111111
Constructor. Use :meth:`.PostgresNode.subscribe()` instead of direct
112112
constructing subscription objects.
@@ -118,8 +118,9 @@ def __init__(self,
118118
(see :meth:`.PostgresNode.publish()`)
119119
dbname: database name used to connect and perform subscription
120120
username: username used to connect to the database
121-
**kwargs: subscription parameters (see ``CREATE SUBSCRIPTION``
122-
in PostgreSQL documentation for more information)
121+
params: subscription parameters (see documentation on `CREATE SUBSCRIPTION
122+
<https://www.postgresql.org/docs/current/static/sql-createsubscription.html>`_
123+
for details)
123124
"""
124125
self.name = name
125126
self.node = node
@@ -138,8 +139,8 @@ def __init__(self,
138139
name, options_string(**conninfo), self.pub.name)
139140

140141
# additional parameters
141-
if kwargs:
142-
query += " with ({})".format(options_string(**kwargs))
142+
if params:
143+
query += " with ({})".format(options_string(**params))
143144

144145
node.safe_psql(query, dbname=dbname, username=username)
145146

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy