From e7001fac602e9e9e102a5a0b3ae856c68e5832db Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 26 Nov 2026 16:47:19 +0000 Subject: [PATCH] Add support for the publish_generated_columns option to publications. #9049 PostgreSQL 18 adds the publish_generated_columns publication option, which takes 'none' (the default) or 'stored'. Add it to the publication dialog for PostgreSQL 18 and later, with new 18_plus SQL templates for create, alter and properties, and emit it in the reverse-engineered SQL when set to 'stored'. Closes #9049 --- docs/en_US/publication_dialog.rst | 1 + .../publications/static/js/publication.ui.js | 13 + .../publications/pg/18_plus/sql/create.sql | 29 + .../pg/18_plus/sql/properties.sql | 10 + .../publications/pg/18_plus/sql/update.sql | 73 ++ .../publications/ppas/18_plus/sql/create.sql | 29 + .../ppas/18_plus/sql/properties.sql | 10 + .../publications/ppas/18_plus/sql/update.sql | 73 ++ .../alter_publication_gencols_none.sql | 7 + .../alter_publication_gencols_none_msql.sql | 2 + .../alter_publication_gencols_stored.sql | 7 + .../alter_publication_gencols_stored_msql.sql | 2 + .../create_publication_gencols_stored.sql | 7 + ...create_publication_gencols_stored_msql.sql | 3 + .../publications/tests/18_plus/test.json | 700 ++++++++++++++++++ 15 files changed, 966 insertions(+) create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/create.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/properties.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/update.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/create.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/properties.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/update.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/test.json diff --git a/docs/en_US/publication_dialog.rst b/docs/en_US/publication_dialog.rst index 8b043311f83..928479233ae 100644 --- a/docs/en_US/publication_dialog.rst +++ b/docs/en_US/publication_dialog.rst @@ -49,6 +49,7 @@ Click the *Options* tab to continue. Use the *Options* tab to set option properties for the publication: * Use the *With* section to determine which DML operations will be published by the new publication to the subscribers. Move the switch next to *INSERT*, *UPDATE*, *DELETE*, or *TRUNCATE* to *No* if you do not want to replicate any of these DML operations from Publication to Subscription. By default, all the switches are set to *Yes* allowing all the DML operations. +* With PostgreSQL 18 forward, use the *Publish generated columns* field to specify whether the generated columns present in the tables associated with the publication should be replicated. Select *None* (the default) to replicate no generated columns, or *Stored* to replicate stored generated columns. .. note:: A published table must have a “replica identity” configured in order to be able to replicate UPDATE and DELETE operations. You can change with ALTER TABLE statement. For more information on replica identity see `Logical Replication Publication `_. diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/static/js/publication.ui.js b/web/pgadmin/browser/server_groups/servers/databases/publications/static/js/publication.ui.js index 8f829956db4..07a5f2dde11 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/publications/static/js/publication.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/static/js/publication.ui.js @@ -37,6 +37,18 @@ export class DefaultWithSchema extends BaseUISchema { id: 'publish_via_partition_root', label: gettext('Publish via root?'), type: 'switch', group: gettext('With'), min_version: 130000, + },{ + id: 'publish_generated_columns', label: gettext('Publish generated columns'), + type: 'select', group: gettext('With'), + mode: ['create','edit', 'properties'], + options: [ + {label: gettext('None'), value: 'none'}, + {label: gettext('Stored'), value: 'stored'}, + ], + controlProps: { allowClear: false }, + min_version: 180000, + helpMessage: gettext('Specifies whether the stored generated columns present in the tables associated with the publication should be replicated.'), + helpMessageMode: ['edit', 'create'], }, ]; } @@ -171,6 +183,7 @@ export default class PublicationSchema extends BaseUISchema { evnt_truncate:true, only_table: undefined, publish_via_partition_root: false, + publish_generated_columns: 'none', ...initValues, }); diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/create.sql new file mode 100644 index 00000000000..9ef0b741bc1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/create.sql @@ -0,0 +1,29 @@ +{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %} +{% set add_comma_after_insert = 'insert' %} +{% endif %} +{% if data.evnt_truncate %} +{% set add_comma_after_delete = 'delete' %} +{% endif %} +{% if data.evnt_delete or data.evnt_truncate%} +{% set add_comma_after_update = 'update' %} +{% endif %} +{% if data.publish_via_partition_root%} +{% set add_comma_after_truncate = 'truncate' %} +{% endif %} +{% set publish_gencols = data.publish_generated_columns == 'stored' %} +{### Create PUBLICATION ###} +CREATE PUBLICATION {{ conn|qtIdent(data.name) }} +{% if data.all_table %} + FOR ALL TABLES +{% elif data.pubtable or data.pubschema %} + FOR {% if data.pubtable %}TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in data.pubtable %}{% if loop.index != 1 %}, {% endif %}{{pub_table['table_name']}}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{column}}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}{% endif %}{% if data.pubtable and data.pubschema %},{% endif %} +{% if data.pubschema %} + TABLES IN SCHEMA {% for pub_schema in data.pubschema %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %} +{% endif %} + +{% endif %} +{% if data.evnt_insert or data.evnt_update or data.evnt_delete or data.evnt_truncate %} + WITH (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}', publish_via_partition_root = {{ data.publish_via_partition_root|lower }}{% if publish_gencols %}, publish_generated_columns = stored{% endif %}); +{% elif publish_gencols %} + WITH (publish_generated_columns = stored); +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/properties.sql new file mode 100644 index 00000000000..e4ef98cd46e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/properties.sql @@ -0,0 +1,10 @@ +SELECT c.oid AS oid, c.pubname AS name, +pubinsert AS evnt_insert, pubupdate AS evnt_update, pubdelete AS evnt_delete, pubtruncate AS evnt_truncate, +puballtables AS all_table, +pubviaroot AS publish_via_partition_root, +CASE c.pubgencols WHEN 's' THEN 'stored' ELSE 'none' END AS publish_generated_columns, +pga.rolname AS pubowner FROM pg_catalog.pg_publication c +JOIN pg_catalog.pg_roles pga ON c.pubowner= pga.oid +{% if pbid %} + WHERE c.oid = {{ pbid }} +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/update.sql new file mode 100644 index 00000000000..99ec4319f52 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/pg/18_plus/sql/update.sql @@ -0,0 +1,73 @@ +{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %} +{% set add_comma_after_insert = 'insert' %} +{% endif %} +{% if data.evnt_truncate %} +{% set add_comma_after_delete = 'delete' %} +{% endif %} +{% if data.evnt_delete or data.evnt_truncate%} +{% set add_comma_after_update = 'update' %} +{% endif %} +{### Alter publication owner ###} +{% if data.pubowner %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + OWNER TO {{ conn|qtIdent(data.pubowner) }}; + +{% endif %} +{### Alter publication event ###} +{% if (data.evnt_insert is defined and data.evnt_insert != o_data.evnt_insert) or (data.evnt_update is defined and data.evnt_update != o_data.evnt_update) or (data.evnt_delete is defined and data.evnt_delete != o_data.evnt_delete) or (data.evnt_truncate is defined and data.evnt_truncate != o_data.evnt_truncate) %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}'); + +{% endif %} +{### Alter publication partition root ###} +{% if data.publish_via_partition_root is defined and data.publish_via_partition_root != o_data.publish_via_partition_root%} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish_via_partition_root = {{ data.publish_via_partition_root|lower }}); + +{% endif %} +{### Alter publication generated columns ###} +{% if data.publish_generated_columns in ['none', 'stored'] and data.publish_generated_columns != o_data.publish_generated_columns %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish_generated_columns = {{ data.publish_generated_columns }}); + +{% endif %} +{### Alter drop publication table ###} +{% if drop_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + DROP TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in drop_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% endfor %}; + +{% endif %} + +{### Alter drop publication schema ###} +{% if drop_schema %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + DROP TABLES IN SCHEMA {% for pub_schema in drop_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}; + +{% endif %} + +{### Alter update publication table ###} +{% if update_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + SET TABLE {% for pub_table in update_table_data %}{% if loop.index != 1 %}, TABLE {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}; + +{% endif %} + +{### Alter publication table ###} +{% if add_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + ADD TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in add_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}; + +{% endif %} + +{### Alter add publication schema ###} +{% if add_schema %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + ADD TABLES IN SCHEMA {% for pub_schema in add_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}; + +{% endif %} + +{### Alter publication name ###} +{% if data.name != o_data.name %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + RENAME TO {{ conn|qtIdent(data.name) }}; +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/create.sql new file mode 100644 index 00000000000..9ef0b741bc1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/create.sql @@ -0,0 +1,29 @@ +{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %} +{% set add_comma_after_insert = 'insert' %} +{% endif %} +{% if data.evnt_truncate %} +{% set add_comma_after_delete = 'delete' %} +{% endif %} +{% if data.evnt_delete or data.evnt_truncate%} +{% set add_comma_after_update = 'update' %} +{% endif %} +{% if data.publish_via_partition_root%} +{% set add_comma_after_truncate = 'truncate' %} +{% endif %} +{% set publish_gencols = data.publish_generated_columns == 'stored' %} +{### Create PUBLICATION ###} +CREATE PUBLICATION {{ conn|qtIdent(data.name) }} +{% if data.all_table %} + FOR ALL TABLES +{% elif data.pubtable or data.pubschema %} + FOR {% if data.pubtable %}TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in data.pubtable %}{% if loop.index != 1 %}, {% endif %}{{pub_table['table_name']}}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{column}}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}{% endif %}{% if data.pubtable and data.pubschema %},{% endif %} +{% if data.pubschema %} + TABLES IN SCHEMA {% for pub_schema in data.pubschema %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %} +{% endif %} + +{% endif %} +{% if data.evnt_insert or data.evnt_update or data.evnt_delete or data.evnt_truncate %} + WITH (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}', publish_via_partition_root = {{ data.publish_via_partition_root|lower }}{% if publish_gencols %}, publish_generated_columns = stored{% endif %}); +{% elif publish_gencols %} + WITH (publish_generated_columns = stored); +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/properties.sql new file mode 100644 index 00000000000..e4ef98cd46e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/properties.sql @@ -0,0 +1,10 @@ +SELECT c.oid AS oid, c.pubname AS name, +pubinsert AS evnt_insert, pubupdate AS evnt_update, pubdelete AS evnt_delete, pubtruncate AS evnt_truncate, +puballtables AS all_table, +pubviaroot AS publish_via_partition_root, +CASE c.pubgencols WHEN 's' THEN 'stored' ELSE 'none' END AS publish_generated_columns, +pga.rolname AS pubowner FROM pg_catalog.pg_publication c +JOIN pg_catalog.pg_roles pga ON c.pubowner= pga.oid +{% if pbid %} + WHERE c.oid = {{ pbid }} +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/update.sql new file mode 100644 index 00000000000..99ec4319f52 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/templates/publications/ppas/18_plus/sql/update.sql @@ -0,0 +1,73 @@ +{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %} +{% set add_comma_after_insert = 'insert' %} +{% endif %} +{% if data.evnt_truncate %} +{% set add_comma_after_delete = 'delete' %} +{% endif %} +{% if data.evnt_delete or data.evnt_truncate%} +{% set add_comma_after_update = 'update' %} +{% endif %} +{### Alter publication owner ###} +{% if data.pubowner %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + OWNER TO {{ conn|qtIdent(data.pubowner) }}; + +{% endif %} +{### Alter publication event ###} +{% if (data.evnt_insert is defined and data.evnt_insert != o_data.evnt_insert) or (data.evnt_update is defined and data.evnt_update != o_data.evnt_update) or (data.evnt_delete is defined and data.evnt_delete != o_data.evnt_delete) or (data.evnt_truncate is defined and data.evnt_truncate != o_data.evnt_truncate) %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}'); + +{% endif %} +{### Alter publication partition root ###} +{% if data.publish_via_partition_root is defined and data.publish_via_partition_root != o_data.publish_via_partition_root%} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish_via_partition_root = {{ data.publish_via_partition_root|lower }}); + +{% endif %} +{### Alter publication generated columns ###} +{% if data.publish_generated_columns in ['none', 'stored'] and data.publish_generated_columns != o_data.publish_generated_columns %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET + (publish_generated_columns = {{ data.publish_generated_columns }}); + +{% endif %} +{### Alter drop publication table ###} +{% if drop_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + DROP TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in drop_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% endfor %}; + +{% endif %} + +{### Alter drop publication schema ###} +{% if drop_schema %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + DROP TABLES IN SCHEMA {% for pub_schema in drop_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}; + +{% endif %} + +{### Alter update publication table ###} +{% if update_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + SET TABLE {% for pub_table in update_table_data %}{% if loop.index != 1 %}, TABLE {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}; + +{% endif %} + +{### Alter publication table ###} +{% if add_table %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + ADD TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in add_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}; + +{% endif %} + +{### Alter add publication schema ###} +{% if add_schema %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + ADD TABLES IN SCHEMA {% for pub_schema in add_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}; + +{% endif %} + +{### Alter publication name ###} +{% if data.name != o_data.name %} +ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} + RENAME TO {{ conn|qtIdent(data.name) }}; +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none.sql new file mode 100644 index 00000000000..f1713b9b1d1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none.sql @@ -0,0 +1,7 @@ +-- Publication: test_publication_create + +-- DROP PUBLICATION IF EXISTS test_publication_create; + +CREATE PUBLICATION test_publication_create + FOR TABLE public.test_table_publication + WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none_msql.sql new file mode 100644 index 00000000000..abe02cbfb07 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_none_msql.sql @@ -0,0 +1,2 @@ +ALTER PUBLICATION test_publication_create SET + (publish_generated_columns = none); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored.sql new file mode 100644 index 00000000000..1bc20f7d8aa --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored.sql @@ -0,0 +1,7 @@ +-- Publication: test_publication_create + +-- DROP PUBLICATION IF EXISTS test_publication_create; + +CREATE PUBLICATION test_publication_create + FOR TABLE public.test_table_publication + WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored_msql.sql new file mode 100644 index 00000000000..b83513c1363 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/alter_publication_gencols_stored_msql.sql @@ -0,0 +1,2 @@ +ALTER PUBLICATION test_publication_create SET + (publish_generated_columns = stored); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored.sql new file mode 100644 index 00000000000..1bc20f7d8aa --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored.sql @@ -0,0 +1,7 @@ +-- Publication: test_publication_create + +-- DROP PUBLICATION IF EXISTS test_publication_create; + +CREATE PUBLICATION test_publication_create + FOR TABLE public.test_table_publication + WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored_msql.sql new file mode 100644 index 00000000000..0a240eaae76 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/create_publication_gencols_stored_msql.sql @@ -0,0 +1,3 @@ +CREATE PUBLICATION test_publication_create + FOR TABLE public.test_table_publication + WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored); \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/test.json b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/test.json new file mode 100644 index 00000000000..163be0823d7 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/publications/tests/18_plus/test.json @@ -0,0 +1,700 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Table For Publication", + "endpoint": "NODE-table.obj", + "sql_endpoint": "NODE-table.sql_id", + "data": { + "name": "test_table_publication", + "columns": [ + { + "name": "emp_id", + "cltype": "integer", + "is_primary_key": true + }, + { + "name": "name", + "cltype": "text" + }, + { + "name": "salary", + "cltype": "bigint" + } + ], + "is_partitioned": false, + "schema": "public", + "spcname": "pg_default" + }, + "store_object_id": true + }, + { + "type": "create", + "name": "Create Second Table For Publication", + "endpoint": "NODE-table.obj", + "sql_endpoint": "NODE-table.sql_id", + "data": { + "name": "test_table_publication_2", + "columns": [ + { + "name": "dept_id", + "cltype": "integer", + "is_primary_key": true + }, + { + "name": "dept_name", + "cltype": "text" + } + ], + "is_partitioned": false, + "schema": "public", + "spcname": "pg_default" + }, + "store_object_id": true + }, + { + "type": "create", + "name": "Create Schema For Publication", + "endpoint": "NODE-schema.obj", + "sql_endpoint": "NODE-schema.sql_id", + "data": { + "name": "test_schema_publication" + }, + "store_object_id": true + }, + { + "type": "create", + "name": "Create Second Schema For Publication", + "endpoint": "NODE-schema.obj", + "sql_endpoint": "NODE-schema.sql_id", + "data": { + "name": "test_schema_publication_2" + }, + "store_object_id": true + }, + { + "type": "create", + "name": "Create Publication for all tables with insert and update", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": false, + "evnt_truncate": false, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": true, + "only_table": false, + "pubtable": "", + "pubschema": "" + }, + "expected_sql_file": "create_publication.sql", + "expected_msql_file": "create_publication_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication name for all tables", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "name": "alterd_publication" + }, + "expected_sql_file": "alter_publication.sql", + "expected_msql_file": "alter_publication_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication event for all tables", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "evnt_delete": true, + "evnt_truncate": true + }, + "expected_sql_file": "alter_publication_event.sql", + "expected_msql_file": "alter_publication_event_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for all tables", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "alterd_publication" + } + }, + { + "type": "create", + "name": "Create Publication for few tables", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication" + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_few_tables.sql", + "expected_msql_file": "create_publication_few_tables_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via adding new tables", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "added": [ + { + "table_name": "public.test_table_publication_2" + } + ] + } + }, + "expected_sql_file": "alter_publication_add_tables.sql", + "expected_msql_file": "alter_publication_add_tables_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via deleting tables with", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "deleted": [ + { + "table_name": "public.test_table_publication_2" + } + ] + } + }, + "expected_sql_file": "alter_publication_drop_tables.sql", + "expected_msql_file": "alter_publication_drop_tables_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via adding new tables with columns", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "added": [ + { + "table_name": "public.test_table_publication_2", + "columns": [ + "dept_id" + ] + } + ] + } + }, + "expected_sql_file": "alter_publication_add_tables_columns.sql", + "expected_msql_file": "alter_publication_add_tables_columns_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via updating tables with columns", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "changed": [ + { + "table_name": "public.test_table_publication_2", + "columns": [ + "dept_name" + ] + } + ] + } + }, + "expected_sql_file": "alter_publication_set_tables_columns.sql", + "expected_msql_file": "alter_publication_set_tables_columns_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via deleting tables with", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "deleted": [ + { + "table_name": "public.test_table_publication_2" + } + ] + } + }, + "expected_sql_file": "alter_publication_drop_tables.sql", + "expected_msql_file": "alter_publication_drop_tables_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via adding new tables with where", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "added": [ + { + "table_name": "public.test_table_publication_2", + "where": "dept_id=2" + } + ] + } + }, + "expected_sql_file": "alter_publication_add_tables_where.sql", + "expected_msql_file": "alter_publication_add_tables_where_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via updating tables with where", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "changed": [ + { + "table_name": "public.test_table_publication_2", + "where": "dept_name='test'" + } + ] + } + }, + "expected_sql_file": "alter_publication_set_tables_where.sql", + "expected_msql_file": "alter_publication_set_tables_where_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via deleting tables with", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "deleted": [ + { + "table_name": "public.test_table_publication_2" + } + ] + } + }, + "expected_sql_file": "alter_publication_drop_tables.sql", + "expected_msql_file": "alter_publication_drop_tables_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via adding new tables with columns and where", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "added": [ + { + "table_name": "public.test_table_publication_2", + "columns": [ + "dept_id" + ], + "where": "dept_id=2" + } + ] + } + }, + "expected_sql_file": "alter_publication_add_tables_columns_where.sql", + "expected_msql_file": "alter_publication_add_tables_columns_where_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few tables via updating tables with columns and where", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubtable": { + "changed": [ + { + "table_name": "public.test_table_publication_2", + "columns": [ + "dept_name" + ], + "where": "dept_name='test'" + } + ] + } + }, + "expected_sql_file": "alter_publication_set_tables_columns_where.sql", + "expected_msql_file": "alter_publication_set_tables_columns_where_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few schemas", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": "", + "pubschema": [ + "test_schema_publication" + ] + }, + "expected_sql_file": "create_publication_few_schemas.sql", + "expected_msql_file": "create_publication_few_schemas_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few schemas via adding new schemas", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubschema": [ + "test_schema_publication", + "test_schema_publication_2" + ] + }, + "expected_sql_file": "alter_publication_add_schemas.sql", + "expected_msql_file": "alter_publication_add_schemas_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication for few schemas via deleting schemas", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "pubschema": [ + "test_schema_publication_2" + ] + }, + "expected_sql_file": "alter_publication_drop_schemas.sql", + "expected_msql_file": "alter_publication_drop_schemas_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few schemas", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with only", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": true, + "pubtable": [ + { + "table_name": "public.test_table_publication" + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_few_tables_only.sql", + "expected_msql_file": "create_publication_few_tables_only_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with only", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables and few schemas", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication" + } + ], + "pubschema": [ + "test_schema_publication" + ] + }, + "expected_sql_file": "create_publication_few_tables_schemas.sql", + "expected_msql_file": "create_publication_few_tables_schemas_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables and few schemas", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with columns", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication", + "columns": [ + "emp_id", + "name" + ] + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_few_tables_columns.sql", + "expected_msql_file": "create_publication_few_tables_columns_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with columns", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with where", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication", + "where": "emp_id=2 and name='test'" + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_few_tables_where.sql", + "expected_msql_file": "create_publication_few_tables_where_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with where", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with columns and where", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication", + "columns": [ + "emp_id", + "name" + ], + "where": "emp_id=2 and name='test'" + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_few_tables_columns_where.sql", + "expected_msql_file": "create_publication_few_tables_columns_where_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with columns and where", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with where and few schemas", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication", + "where": "emp_id=2 and name='test'" + } + ], + "pubschema": [ + "test_schema_publication" + ] + }, + "expected_sql_file": "create_publication_few_tables_where_schemas.sql", + "expected_msql_file": "create_publication_few_tables_where_schemas_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with where and few schemas", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + }, + { + "type": "create", + "name": "Create Publication for few tables with stored generated columns", + "endpoint": "NODE-publication.obj", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql", + "data": { + "name": "test_publication_create", + "evnt_insert": true, + "evnt_update": true, + "evnt_delete": true, + "evnt_truncate": true, + "pubowner": "", + "publish_via_partition_root": false, + "publish_generated_columns": "stored", + "all_table": false, + "only_table": false, + "pubtable": [ + { + "table_name": "public.test_table_publication" + } + ], + "pubschema": "" + }, + "expected_sql_file": "create_publication_gencols_stored.sql", + "expected_msql_file": "create_publication_gencols_stored_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication generated columns to none", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "publish_generated_columns": "none" + }, + "expected_sql_file": "alter_publication_gencols_none.sql", + "expected_msql_file": "alter_publication_gencols_none_msql.sql" + }, + { + "type": "alter", + "name": "Alter Publication generated columns to stored", + "endpoint": "NODE-publication.obj_id", + "sql_endpoint": "NODE-publication.sql_id", + "msql_endpoint": "NODE-publication.msql_id", + "data": { + "publish_generated_columns": "stored" + }, + "expected_sql_file": "alter_publication_gencols_stored.sql", + "expected_msql_file": "alter_publication_gencols_stored_msql.sql" + }, + { + "type": "delete", + "name": "Drop publication for few tables with stored generated columns", + "endpoint": "NODE-publication.delete_id", + "data": { + "name": "test_publication_create" + } + } + ] +}