Skip to content

Commit

Permalink
Fixed CREATE SUBSCRIPTION's generated query for copy_data parameter w…
Browse files Browse the repository at this point in the history
…hen it is set to false. #6817
  • Loading branch information
anilsahoo20 committed Oct 26, 2023
1 parent 8997f61 commit b798a06
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def create(self, gid, sid, did):

sql = render_template(
"/".join([self.template_path, 'get_position.sql']),
conn=self.conn, subname=data['name']
conn=self.conn, subname=data['name'], did=did
)

status, r_set = self.conn.execute_dict(sql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ CREATE SUBSCRIPTION {{ conn|qtIdent(data.name) }}
PUBLICATION {% for pub in data.pub %}{% if loop.index != 1 %},{% endif %}{{ conn|qtIdent(pub) }}{% endfor %}
{% endif %}

WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data is defined %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
{% if data.create_slot is defined %}create_slot = {{ data.create_slot|lower }}{% if add_semicolon_after_create_slot == 'create_slot' %}, {% endif %}{% endif %}
{% if data.slot_name is defined and data.slot_name != ''%}slot_name = {{ data.slot_name }}{% if add_semicolon_after_slot_name == 'slot_name' %}, {% endif %}{% endif %}{% if data.sync %}synchronous_commit = '{{ data.sync }}', {% endif %}binary = {{ data.binary|lower}}, streaming = '{{ data.streaming}}');
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ CREATE SUBSCRIPTION {{ conn|qtIdent(data.name) }}
PUBLICATION {% for pub in data.pub %}{% if loop.index != 1 %},{% endif %}{{ conn|qtIdent(pub) }}{% endfor %}
{% endif %}

WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data is defined %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
{% if data.create_slot is defined %}create_slot = {{ data.create_slot|lower }}{% if add_semicolon_after_create_slot == 'create_slot' %}, {% endif %}{% endif %}
{% if data.slot_name is defined and data.slot_name != ''%}slot_name = {{ data.slot_name }}{% if add_semicolon_after_slot_name == 'slot_name' %}, {% endif %}{% endif %}{% if data.sync %}synchronous_commit = '{{ data.sync }}', {% endif %}binary = {{ data.binary|lower}}, streaming = '{{ data.streaming}}', two_phase = {{ data.two_phase|lower}}, disable_on_error = {{ data.disable_on_error|lower}});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ CREATE SUBSCRIPTION {{ conn|qtIdent(data.name) }}
PUBLICATION {% for pub in data.pub %}{% if loop.index != 1 %},{% endif %}{{ conn|qtIdent(pub) }}{% endfor %}
{% endif %}

WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data is defined %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
{% if data.create_slot is defined %}create_slot = {{ data.create_slot|lower }}{% if add_semicolon_after_create_slot == 'create_slot' %}, {% endif %}{% endif %}
{% if data.slot_name is defined and data.slot_name != ''%}slot_name = {{ data.slot_name }}{% if add_semicolon_after_slot_name == 'slot_name' %}, {% endif %}{% endif %}{% if data.sync %}synchronous_commit = '{{ data.sync }}', {% endif %}binary = {{ data.binary|lower}}, streaming = '{{ data.streaming}}', two_phase = {{ data.two_phase|lower}}, disable_on_error = {{ data.disable_on_error|lower}}, run_as_owner = {{ data.run_as_owner|lower}}, password_required = {{ data.password_required|lower}}, origin = '{{ data.origin}}');
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ CREATE SUBSCRIPTION {{ conn|qtIdent(data.name) }}
PUBLICATION {% for pub in data.pub %}{% if loop.index != 1 %},{% endif %}{{ conn|qtIdent(pub) }}{% endfor %}
{% endif %}

WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
WITH ({% if data.connect is defined %}connect = {{ data.connect|lower}}, {% endif %}enabled = {{ data.enabled|lower}}, {% if data.copy_data is defined %}copy_data = {{ data.copy_data|lower}}{% if add_semicolon_after_copy_data == 'copy_data' %}, {% endif %}{% endif %}
{% if data.create_slot is defined %}create_slot = {{ data.create_slot|lower }}{% if add_semicolon_after_create_slot == 'create_slot' %}, {% endif %}{% endif %}
{% if data.slot_name is defined and data.slot_name != ''%}slot_name = {{ data.slot_name }}{% if add_semicolon_after_slot_name == 'slot_name' %}, {% endif %}{% endif %}{% if data.sync %}synchronous_commit = '{{ data.sync }}'{% endif %});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT oid, subname AS name FROM pg_catalog.pg_subscription WHERE subname = '{{ subname }}';
SELECT oid, subname AS name FROM pg_catalog.pg_subscription WHERE subname = '{{ subname }}' and subdbid={{did}} :: oid;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE SUBSCRIPTION test_create_subscription
CONNECTION 'host=localhost port=5434 user=postgres dbname=postgres connect_timeout=10 password=xxxxxx sslmode=prefer'
PUBLICATION test_pub
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True');
WITH (connect = false, enabled = false, copy_data = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True');
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
"name": "Alter parameters of subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"binary": false,
"streaming": false
},
"expected_sql_file": "alter_parameters.sql"
"expected_sql_file": "alter_parameters.sql",
"expected_msql_file": "alter_parameters_msql.sql"
},
{
"type": "delete",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE SUBSCRIPTION test_create_subscription
CONNECTION 'host=localhost port=5434 user=postgres dbname=postgres connect_timeout=10 password=xxxxxx sslmode=prefer'
PUBLICATION test_pub
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True', two_phase = true, disable_on_error = true);
WITH (connect = false, enabled = false, copy_data = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True', two_phase = true, disable_on_error = true);
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"name": "Alter parameters of subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"sync": "off",
"binary": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE SUBSCRIPTION test_create_subscription
CONNECTION 'host=localhost port=5434 user=postgres dbname=postgres connect_timeout=10 password=xxxxxx sslmode=prefer'
PUBLICATION test_pub
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True', two_phase = true, disable_on_error = true, run_as_owner = true, password_required = true, origin = 'any');
WITH (connect = false, enabled = false, copy_data = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply', binary = true, streaming = 'True', two_phase = true, disable_on_error = true, run_as_owner = true, password_required = true, origin = 'any');
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"name": "Alter parameters of subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"sync": "off",
"binary": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-- DROP SUBSCRIPTION IF EXISTS test_alter_subscription;

CREATE SUBSCRIPTION test_alter_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=edb'
CONNECTION 'host=localhost port=5432 user=postgres dbname=edb connect_timeout=10 sslmode=prefer'
PUBLICATION sample__1
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply');
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER SUBSCRIPTION test_alter_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=edb';
CONNECTION 'host=localhost port=5432 user=postgres dbname=edb connect_timeout=10 sslmode=prefer';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-- DROP SUBSCRIPTION IF EXISTS test_alter_subscription;

CREATE SUBSCRIPTION test_alter_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres'
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres connect_timeout=10 sslmode=prefer'
PUBLICATION sample__1
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'off');
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-- DROP SUBSCRIPTION IF EXISTS test_alter_subscription;

CREATE SUBSCRIPTION test_alter_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres'
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres connect_timeout=10 sslmode=prefer'
PUBLICATION sample__1
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'remote_apply');
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-- DROP SUBSCRIPTION IF EXISTS test_create_subscription;

CREATE SUBSCRIPTION test_create_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres'
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres connect_timeout=10 sslmode=prefer'
PUBLICATION sample__1
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'off');
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE SUBSCRIPTION test_create_subscription
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres password=xxxxxx'
CONNECTION 'host=localhost port=5432 user=postgres dbname=postgres connect_timeout=10 password=xxxxxx sslmode=prefer'
PUBLICATION sample__1
WITH (connect = false, enabled = false, create_slot = false, slot_name = None, synchronous_commit = 'off');
WITH (connect = false, enabled = false, copy_data = false, create_slot = false, slot_name = None, synchronous_commit = 'off');
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"port": 5432,
"password": "edb",
"sync": "off",
"connect_timeout": 10,
"sslmode": "prefer",
"pub": ["sample__1"]
},
"expected_sql_file": "create_subscription.sql",
Expand All @@ -31,6 +33,7 @@
"name": "Alter Subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"name": "test_alter_subscription"
},
Expand All @@ -42,6 +45,7 @@
"name": "Alter sync of subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"sync": "remote_apply"
},
Expand All @@ -54,6 +58,7 @@
"name": "Alter maintainance DB in connection string of subscription",
"endpoint": "NODE-subscription.obj_id",
"sql_endpoint": "NODE-subscription.sql_id",
"msql_endpoint": "NODE-subscription.msql_id",
"data": {
"db": "edb"
},
Expand Down

0 comments on commit b798a06

Please sign in to comment.