From 5e54f20578c9620c6b92a442c13c79c00a3db3a8 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Wed, 4 Sep 2019 18:33:07 +0530 Subject: [PATCH] Add Reverse Engineered and Modified SQL tests for Foreign Tables. Fixes #4618. --- docs/en_US/release_notes_4_13.rst | 1 + .../schemas/foreign_tables/__init__.py | 5 + .../sql/12_plus/get_constraints.sql | 3 +- .../foreign_tables/sql/9.2_plus/acl.sql | 3 +- .../foreign_tables/sql/9.2_plus/update.sql | 37 ++- .../foreign_tables/sql/9.5_plus/update.sql | 42 ++- .../tests/pg/9.2_plus/alter_add_opts.sql | 16 ++ .../tests/pg/9.2_plus/alter_add_opts_msql.sql | 5 + .../tests/pg/9.2_plus/alter_add_priv.sql | 20 ++ .../tests/pg/9.2_plus/alter_add_priv_msql.sql | 1 + .../tests/pg/9.2_plus/alter_col_opts.sql | 19 ++ .../tests/pg/9.2_plus/alter_col_opts_msql.sql | 14 + .../pg/9.2_plus/alter_comment_add_columns.sql | 15 + .../alter_comment_add_columns_msql.sql | 8 + .../pg/9.2_plus/alter_remove_opts_priv.sql | 17 ++ .../9.2_plus/alter_remove_opts_priv_msql.sql | 4 + .../create_foreign_table_with_all_options.sql | 20 ++ ...te_foreign_table_with_all_options_msql.sql | 14 + .../tests/pg/9.2_plus/test_foreign_table.json | 242 ++++++++++++++++ .../tests/pg/9.5_plus/alter_add_cons_opts.sql | 19 ++ .../pg/9.5_plus/alter_add_cons_opts_msql.sql | 8 + .../tests/pg/9.5_plus/alter_add_priv.sql | 23 ++ .../tests/pg/9.5_plus/alter_add_priv_msql.sql | 1 + .../tests/pg/9.5_plus/alter_col_opts.sql | 22 ++ .../tests/pg/9.5_plus/alter_col_opts_msql.sql | 14 + .../pg/9.5_plus/alter_comment_add_columns.sql | 15 + .../alter_comment_add_columns_msql.sql | 8 + .../9.5_plus/alter_remove_opts_priv_cons.sql | 17 ++ .../alter_remove_opts_priv_cons_msql.sql | 7 + .../create_foreign_table_with_all_options.sql | 23 ++ ...te_foreign_table_with_all_options_msql.sql | 17 ++ .../tests/pg/9.5_plus/test_foreign_table.json | 264 ++++++++++++++++++ .../tests/ppas/9.2_plus/alter_add_opts.sql | 16 ++ .../ppas/9.2_plus/alter_add_opts_msql.sql | 5 + .../tests/ppas/9.2_plus/alter_add_priv.sql | 20 ++ .../ppas/9.2_plus/alter_add_priv_msql.sql | 1 + .../tests/ppas/9.2_plus/alter_col_opts.sql | 19 ++ .../ppas/9.2_plus/alter_col_opts_msql.sql | 14 + .../9.2_plus/alter_comment_add_columns.sql | 15 + .../alter_comment_add_columns_msql.sql | 8 + .../ppas/9.2_plus/alter_remove_opts_priv.sql | 17 ++ .../9.2_plus/alter_remove_opts_priv_msql.sql | 4 + .../create_foreign_table_with_all_options.sql | 20 ++ ...te_foreign_table_with_all_options_msql.sql | 14 + .../ppas/9.2_plus/test_foreign_table.json | 242 ++++++++++++++++ .../ppas/9.5_plus/alter_add_cons_opts.sql | 19 ++ .../9.5_plus/alter_add_cons_opts_msql.sql | 8 + .../tests/ppas/9.5_plus/alter_add_priv.sql | 23 ++ .../ppas/9.5_plus/alter_add_priv_msql.sql | 1 + .../tests/ppas/9.5_plus/alter_col_opts.sql | 22 ++ .../ppas/9.5_plus/alter_col_opts_msql.sql | 14 + .../9.5_plus/alter_comment_add_columns.sql | 15 + .../alter_comment_add_columns_msql.sql | 8 + .../9.5_plus/alter_remove_opts_priv_cons.sql | 17 ++ .../alter_remove_opts_priv_cons_msql.sql | 7 + .../create_foreign_table_with_all_options.sql | 23 ++ ...te_foreign_table_with_all_options_msql.sql | 17 ++ .../ppas/9.5_plus/test_foreign_table.json | 264 ++++++++++++++++++ 58 files changed, 1714 insertions(+), 43 deletions(-) create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/test_foreign_table.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/test_foreign_table.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/test_foreign_table.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options_msql.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/test_foreign_table.json diff --git a/docs/en_US/release_notes_4_13.rst b/docs/en_US/release_notes_4_13.rst index ca16616fc..a7346e20d 100644 --- a/docs/en_US/release_notes_4_13.rst +++ b/docs/en_US/release_notes_4_13.rst @@ -21,6 +21,7 @@ Housekeeping | `Issue #4576 `_ - Add Reverse Engineered SQL tests for Views. | `Issue #4600 `_ - Add Reverse Engineered SQL tests for Rules. | `Issue #4617 `_ - Add Reverse Engineered and Modified SQL tests for Foreign Servers. +| `Issue #4618 `_ - Add Reverse Engineered and Modified SQL tests for Foreign Tables. | `Issue #4619 `_ - Add Reverse Engineered and Modified SQL tests for FTS Templates. | `Issue #4627 `_ - Add Reverse Engineered and Modified SQL tests for User Mappings. | `Issue #4690 `_ - Add Modified SQL tests for Resource Group. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py index 41f8cfd6a..75702a557 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py @@ -827,6 +827,11 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): data['columns'] = col_data + # Parse Privileges + if 'acl' in data: + data['acl'] = parse_priv_to_db(data['acl'], + ["a", "r", "w", "x"]) + SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, is_sql=True) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/12_plus/get_constraints.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/12_plus/get_constraints.sql index b738c7880..088cd4697 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/12_plus/get_constraints.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/12_plus/get_constraints.sql @@ -1,5 +1,6 @@ SELECT - oid as conoid, conname, contype, pg_get_constraintdef(oid, true) as consrc, + oid as conoid, conname, contype, + BTRIM(substring(pg_get_constraintdef(oid, true) from '\(.+\)'), '()') as consrc, connoinherit, convalidated, conislocal FROM pg_constraint diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/acl.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/acl.sql index 0a5c4fcbd..2322a4c4b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/acl.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/acl.sql @@ -32,4 +32,5 @@ FROM ) d LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid) LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid) -GROUP BY g.rolname, gt.rolname; +GROUP BY g.rolname, gt.rolname +ORDER BY grantee; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/update.sql index 564afe498..8f30a59e9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.2_plus/update.sql @@ -6,22 +6,22 @@ {% if data.name != o_data.name %} ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, o_data.name) }} RENAME TO {{ conn|qtIdent(data.name) }}; + {% set name = data.name %} {% endif %} {% endif -%} {% if data.owner %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OWNER TO {{ data.owner }}; + {% endif -%} {% if data.columns %} {% for c in data.columns.deleted %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} DROP COLUMN {{conn|qtIdent(c.attname)}}; + {% endfor -%} {% for c in data.columns.added %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ADD COLUMN {{conn|qtIdent(c.attname)}} {{ c.datatype }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %} {% if c.coloptions %} @@ -31,38 +31,38 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% if c.attnotnull %} NOT NULL{% else %} NULL{% endif %} {% if c.typdefault is defined and c.typdefault is not none %} DEFAULT {{c.typdefault}}{% endif %} {% if c.collname %} COLLATE {{c.collname}}{% endif %}; + {% endfor -%} {% for c in data.columns.changed %} {% set col_name = o_data['columns'][c.attnum]['attname'] %} {% if c.attname != o_data['columns'][c.attnum]['attname'] %} {% set col_name = c.attname %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} RENAME COLUMN {{conn|qtIdent(o_data['columns'][c.attnum]['attname'])}} TO {{conn|qtIdent(c.attname)}}; + {% endif %} {% if c.attnotnull != o_data['columns'][c.attnum]['attnotnull'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.attnotnull %} SET{% else %} DROP{% endif %} NOT NULL; + {% endif %} {% if c.datatype != o_data['columns'][c.attnum]['datatype'] or c.typlen != o_data['columns'][c.attnum]['typlen'] or c.precision != o_data['columns'][c.attnum]['precision'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}} TYPE {{ c.datatype }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %}; + {% endif %} {% if c.typdefault is defined and c.typdefault != o_data['columns'][c.attnum]['typdefault'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault is defined and c.typdefault != '' %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %}; + {% endif %} {% if c.attstattarget != o_data['columns'][c.attnum]['attstattarget'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}} SET STATISTICS {% if c.attstattarget %}{{c.attstattarget}}{% else %}-1{% endif %}; + {% endif %} {% if c.coloptions_updated %} - {% for o in c.coloptions_updated.deleted %} {% if o.option %} {% if loop.first %}ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} @@ -86,58 +86,58 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% endif -%} {% if data.constraints %} {% for c in data.constraints.deleted %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} DROP CONSTRAINT {{conn|qtIdent(c.conname)}}; + {% endfor %} {% for c in data.constraints.added %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ADD CONSTRAINT {{conn|qtIdent(c.conname)}} {% if c.consrc %} CHECK ({{c.consrc}}){% endif %} {% if c.connoinherit %} NO INHERIT{% endif %}; + {% endfor %} {% endif -%} {% if data.ftoptions %} {% for o in data.ftoptions.deleted %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS ( DROP {{o.option}}); + {% endif %} {% endfor %} {% for o in data.ftoptions.added %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS (ADD {{o.option}} {{o.value|qtLiteral}}); + {% endif %} {% endfor %} {% for o in data.ftoptions.changed %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS (SET {{o.option}} {{o.value|qtLiteral}}); + {% endif %} {% endfor %} {% endif -%} {% if data.acl %} {% if 'deleted' in data.acl %} {% for priv in data.acl.deleted %} - {{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, name, o_data.basensp) }} + {% endfor %} {% endif -%} {% if 'changed' in data.acl %} {% for priv in data.acl.changed %} - {{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, name, o_data.basensp) }} {{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.basensp) }} + {% endfor %} {% endif -%} {% if 'added' in data.acl %} {% for priv in data.acl.added %} - {{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.basensp) }} + {% endfor %} {% endif %} {% endif -%} @@ -161,12 +161,11 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% endfor %} {% endif -%} {% if data.description is defined and data.description != o_data.description%} - COMMENT ON FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} IS {{ data.description|qtLiteral }}; + {% endif -%} {% if data.basensp %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} SET SCHEMA {{ conn|qtIdent(data.basensp) }}; {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.5_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.5_plus/update.sql index ed97ae63a..fa84c1e2b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.5_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_tables/sql/9.5_plus/update.sql @@ -5,23 +5,24 @@ {% if data.name %}{% if data.name != o_data.name %} ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, o_data.name) }} RENAME TO {{ conn|qtIdent(data.name) }}; + {% set name = data.name %} {% endif %}{% endif %} {% if data.owner %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OWNER TO {{ data.owner }}; + {% endif %} {% if data.columns %} {% for c in data.columns.deleted %} {% if (not c.inheritedfrom or c.inheritedfrom =='' or c.inheritedfrom == None or c.inheritedfrom == 'None' ) %} ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} DROP COLUMN {{conn|qtIdent(c.attname)}}; + {% endif %} {% endfor -%} {% for c in data.columns.added %} {% if (not c.inheritedfrom or c.inheritedfrom =='' or c.inheritedfrom == None or c.inheritedfrom == 'None' ) %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ADD COLUMN {{conn|qtIdent(c.attname)}} {{ c.datatype }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %} {% if c.coloptions %} @@ -31,39 +32,39 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% if c.attnotnull %} NOT NULL{% else %} NULL{% endif %} {% if c.typdefault is defined and c.typdefault is not none %} DEFAULT {{c.typdefault}}{% endif %} {% if c.collname %} COLLATE {{c.collname}}{% endif %}; + {% endif %} {% endfor -%} {% for c in data.columns.changed %} {% set col_name = o_data['columns'][c.attnum]['attname'] %} {% if c.attname != o_data['columns'][c.attnum]['attname'] %} {% set col_name = c.attname %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} RENAME COLUMN {{conn|qtIdent(o_data['columns'][c.attnum]['attname'])}} TO {{conn|qtIdent(c.attname)}}; + {% endif %} {% if c.attnotnull != o_data['columns'][c.attnum]['attnotnull'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.attnotnull %} SET{% else %} DROP{% endif %} NOT NULL; + {% endif %} {% if c.datatype != o_data['columns'][c.attnum]['datatype'] or c.typlen != o_data['columns'][c.attnum]['typlen'] or c.precision != o_data['columns'][c.attnum]['precision'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}} TYPE {{ c.datatype }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %}; + {% endif %} {% if c.typdefault is defined and c.typdefault != o_data['columns'][c.attnum]['typdefault'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault is defined and c.typdefault != '' %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %}; + {% endif %} {% if c.attstattarget != o_data['columns'][c.attnum]['attstattarget'] %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ALTER COLUMN {{conn|qtIdent(col_name)}} SET STATISTICS {% if c.attstattarget %}{{c.attstattarget}}{% else %}-1{% endif %}; + {% endif %} {% if c.coloptions_updated %} - {% for o in c.coloptions_updated.deleted %} {% if o.option %} {% if loop.first %}ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} @@ -93,7 +94,6 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% endif %} {% for i in data.inherits %} {% if i not in inherits %}{% if i %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} INHERIT {{i}}; {% endif %} {% endif %} @@ -106,50 +106,49 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} INHERIT {{i}}; {% set inherits = data.inherits %} {% endif %} {% for i in o_data.inherits %}{% if i not in inherits %}{% if i %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} NO INHERIT {{i}};{% endif %} {% endif %} {% endfor %} {% endif %} {% if data.constraints %} {% for c in data.constraints.deleted %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} DROP CONSTRAINT {{conn|qtIdent(c.conname)}}; + {% endfor -%} {% for c in data.constraints.added %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} ADD CONSTRAINT {{ conn|qtIdent(c.conname) }} CHECK ({{ c.consrc }}){% if not c.convalidated %} NOT VALID{% endif %}{% if c.connoinherit %} NO INHERIT{% endif %}; + {% endfor %} {% for c in data.constraints.changed %} {% if c.convalidated %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} VALIDATE CONSTRAINT {{ conn|qtIdent(c.conname) }}; + {% endif %} {% endfor %} {% endif %} {% if data.ftoptions %} {% for o in data.ftoptions.deleted %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS ( DROP {{o.option}}); + {% endif %} {% endfor %} {% for o in data.ftoptions.added %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS (ADD {{o.option}} {{o.value|qtLiteral}}); + {% endif %} {% endfor %} {% for o in data.ftoptions.changed %} {% if o.option and o.value %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} OPTIONS (SET {{o.option}} {{o.value|qtLiteral}}); + {% endif %} {% endfor %} {% endif -%} @@ -173,34 +172,33 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} {% endfor %} {% endif -%} {% if data.description is defined and data.description != o_data.description%} - COMMENT ON FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} -IS {{ data.description|qtLiteral }}; + IS {{ data.description|qtLiteral }}; + {% endif -%} {% if data.acl %} {% if 'deleted' in data.acl %} {% for priv in data.acl.deleted %} - {{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, name, o_data.basensp) }} + {% endfor %} {% endif -%} {% if 'changed' in data.acl %} {% for priv in data.acl.changed %} - {{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, name, o_data.basensp) }} {{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.basensp) }} + {% endfor %} {% endif -%} {% if 'added' in data.acl %} {% for priv in data.acl.added %} - {{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.basensp) }} + {% endfor %} {% endif %} {% endif -%} {% if data.basensp %} - ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }} SET SCHEMA {{ conn|qtIdent(data.basensp) }}; {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts.sql new file mode 100644 index 000000000..a64ce6de3 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts.sql @@ -0,0 +1,16 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts_msql.sql new file mode 100644 index 000000000..135e51c3d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_opts_msql.sql @@ -0,0 +1,5 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD schema_name 'public'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD table_name 'test_table'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv.sql new file mode 100644 index 000000000..64d3f6583 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv.sql @@ -0,0 +1,20 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv_msql.sql new file mode 100644 index 000000000..2c6f1712d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_add_priv_msql.sql @@ -0,0 +1 @@ +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts.sql new file mode 100644 index 000000000..766836157 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts.sql @@ -0,0 +1,19 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'test_public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts_msql.sql new file mode 100644 index 000000000..cdb8a27dd --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_col_opts_msql.sql @@ -0,0 +1,14 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP COLUMN col2; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 DROP NOT NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 TYPE integer; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 SET STATISTICS -1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (SET schema_name 'test_public'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns.sql new file mode 100644 index 000000000..9a24215dc --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns.sql @@ -0,0 +1,15 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns_msql.sql new file mode 100644 index 000000000..9041626b6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_comment_add_columns_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col1 bigint NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col2 text NULL; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv.sql new file mode 100644 index 000000000..f31160f4d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv.sql @@ -0,0 +1,17 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv_msql.sql new file mode 100644 index 000000000..56653c630 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/alter_remove_opts_priv_msql.sql @@ -0,0 +1,4 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS ( DROP schema_name); + +REVOKE ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options.sql new file mode 100644 index 000000000..e4c99eb36 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options.sql @@ -0,0 +1,20 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options_msql.sql new file mode 100644 index 000000000..cb3977c0e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/create_foreign_table_with_all_options_msql.sql @@ -0,0 +1,14 @@ +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/test_foreign_table.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/test_foreign_table.json new file mode 100644 index 000000000..a0e5b5199 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.2_plus/test_foreign_table.json @@ -0,0 +1,242 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create FDW for foreign table", + "endpoint": "NODE-foreign_data_wrapper.obj", + "sql_endpoint": "NODE-foreign_data_wrapper.sql_id", + "data": { + "name": "test_fdw_for_foreign_table", + "fdwacl": [], + "fdwoptions": [] + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create foreign server for foreign table", + "endpoint": "NODE-foreign_server.obj", + "sql_endpoint": "NODE-foreign_server.sql_id", + "data": { + "name":"test_fs_for_foreign_table" + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create Foreign Table with all options", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner":"postgres", + "schema": "public", + "basensp":"public", + "description":"Test Comment", + "ftsrvname":"test_fs_for_foreign_table", + "columns":[{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }], + "ftoptions":[{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }], + "acl":[{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"w", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"x", + "privilege":true, + "with_grant":false + }] + }] + }, + "expected_sql_file": "create_foreign_table_with_all_options.sql", + "expected_msql_file": "create_foreign_table_with_all_options_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, + { + "type": "create", + "name": "Create Foreign Table", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "basensp": "public", + "ftsrvname": "test_fs_for_foreign_table", + "columns": [] + } + }, { + "type": "alter", + "name": "Alter Foreign Table comment and add columns", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "description":"Test Comment", + "columns": { + "added": [{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }] + } + }, + "expected_sql_file": "alter_comment_add_columns.sql", + "expected_msql_file": "alter_comment_add_columns_msql.sql" + },{ + "type": "alter", + "name": "Alter Foreign Table add options", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "added": [{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }] + } + }, + "expected_sql_file": "alter_add_opts.sql", + "expected_msql_file": "alter_add_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table add privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "added": [{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + } + }, + "expected_sql_file": "alter_add_priv.sql", + "expected_msql_file": "alter_add_priv_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table change option and column", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "changed": [{ + "option":"schema_name", + "value":"test_public" + }] + }, + "columns": { + "changed": [{ + "attname": "col1", + "attnum": 1, + "attoptions": null, + "collname": "", + "coloptions": [], + "datatype": "integer", + "fulltype": "bigint" + }], + "deleted": [{ + "attname":"col2", + "datatype":"text" + }] + } + }, + "expected_sql_file": "alter_col_opts.sql", + "expected_msql_file": "alter_col_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table remove option, privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "deleted": [{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + }, + "ftoptions": { + "deleted": [{ + "option":"schema_name", + "value":"public" + }] + } + }, + "expected_sql_file": "alter_remove_opts_priv.sql", + "expected_msql_file": "alter_remove_opts_priv_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, { + "type": "delete", + "name": "Drop foreign server", + "endpoint": "NODE-foreign_server.delete_id", + "data": { + "name": "test_fs_for_foreign_table" + } + }, { + "type": "delete", + "name": "Drop FDW", + "endpoint": "NODE-foreign_data_wrapper.delete_id", + "data": { + "name": "test_fdw_for_foreign_table" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts.sql new file mode 100644 index 000000000..521633774 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts.sql @@ -0,0 +1,19 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts_msql.sql new file mode 100644 index 000000000..1160cd6b3 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_cons_opts_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD schema_name 'public'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD table_name 'test_table'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv.sql new file mode 100644 index 000000000..93f4348ca --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv.sql @@ -0,0 +1,23 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv_msql.sql new file mode 100644 index 000000000..2c6f1712d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_add_priv_msql.sql @@ -0,0 +1 @@ +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts.sql new file mode 100644 index 000000000..56df2575c --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts.sql @@ -0,0 +1,22 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'test_public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts_msql.sql new file mode 100644 index 000000000..cdb8a27dd --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_col_opts_msql.sql @@ -0,0 +1,14 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP COLUMN col2; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 DROP NOT NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 TYPE integer; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 SET STATISTICS -1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (SET schema_name 'test_public'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns.sql new file mode 100644 index 000000000..9a24215dc --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns.sql @@ -0,0 +1,15 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns_msql.sql new file mode 100644 index 000000000..9041626b6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_comment_add_columns_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col1 bigint NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col2 text NULL; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons.sql new file mode 100644 index 000000000..f31160f4d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons.sql @@ -0,0 +1,17 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons_msql.sql new file mode 100644 index 000000000..007e93bc3 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/alter_remove_opts_priv_cons_msql.sql @@ -0,0 +1,7 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP CONSTRAINT cons1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS ( DROP schema_name); + +REVOKE ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options.sql new file mode 100644 index 000000000..a6e0d77e4 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options.sql @@ -0,0 +1,23 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options_msql.sql new file mode 100644 index 000000000..13494a793 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/create_foreign_table_with_all_options_msql.sql @@ -0,0 +1,17 @@ +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/test_foreign_table.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/test_foreign_table.json new file mode 100644 index 000000000..ba800abf8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/pg/9.5_plus/test_foreign_table.json @@ -0,0 +1,264 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create FDW for foreign table", + "endpoint": "NODE-foreign_data_wrapper.obj", + "sql_endpoint": "NODE-foreign_data_wrapper.sql_id", + "data": { + "name": "test_fdw_for_foreign_table", + "fdwacl": [], + "fdwoptions": [] + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create foreign server for foreign table", + "endpoint": "NODE-foreign_server.obj", + "sql_endpoint": "NODE-foreign_server.sql_id", + "data": { + "name":"test_fs_for_foreign_table" + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create Foreign Table with all options", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner":"postgres", + "schema": "public", + "basensp":"public", + "description":"Test Comment", + "ftsrvname":"test_fs_for_foreign_table", + "columns":[{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }], + "constraints":[{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }], + "ftoptions":[{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }], + "acl":[{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"w", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"x", + "privilege":true, + "with_grant":false + }] + }] + }, + "expected_sql_file": "create_foreign_table_with_all_options.sql", + "expected_msql_file": "create_foreign_table_with_all_options_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, + { + "type": "create", + "name": "Create Foreign Table", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "basensp": "public", + "ftsrvname": "test_fs_for_foreign_table", + "columns": [] + } + }, { + "type": "alter", + "name": "Alter Foreign Table comment and add columns", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "description":"Test Comment", + "columns": { + "added": [{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }] + } + }, + "expected_sql_file": "alter_comment_add_columns.sql", + "expected_msql_file": "alter_comment_add_columns_msql.sql" + },{ + "type": "alter", + "name": "Alter Foreign Table add constraints and options", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "constraints": { + "added": [{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }] + }, + "ftoptions": { + "added": [{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }] + } + }, + "expected_sql_file": "alter_add_cons_opts.sql", + "expected_msql_file": "alter_add_cons_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table add privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "added": [{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + } + }, + "expected_sql_file": "alter_add_priv.sql", + "expected_msql_file": "alter_add_priv_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table change option and column", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "changed": [{ + "option":"schema_name", + "value":"test_public" + }] + }, + "columns": { + "changed": [{ + "attname": "col1", + "attnum": 1, + "attoptions": null, + "collname": "", + "coloptions": [], + "datatype": "integer", + "fulltype": "bigint" + }], + "deleted": [{ + "attname":"col2", + "datatype":"text" + }] + } + }, + "expected_sql_file": "alter_col_opts.sql", + "expected_msql_file": "alter_col_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table remove option, constraint, privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "deleted": [{ + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + }, + "constraints": { + "deleted": [{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }] + }, + "ftoptions": { + "deleted": [{ + "option":"schema_name", + "value":"public" + }] + } + }, + "expected_sql_file": "alter_remove_opts_priv_cons.sql", + "expected_msql_file": "alter_remove_opts_priv_cons_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, { + "type": "delete", + "name": "Drop foreign server", + "endpoint": "NODE-foreign_server.delete_id", + "data": { + "name": "test_fs_for_foreign_table" + } + }, { + "type": "delete", + "name": "Drop FDW", + "endpoint": "NODE-foreign_data_wrapper.delete_id", + "data": { + "name": "test_fdw_for_foreign_table" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts.sql new file mode 100644 index 000000000..19e6026f1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts.sql @@ -0,0 +1,16 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts_msql.sql new file mode 100644 index 000000000..135e51c3d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_opts_msql.sql @@ -0,0 +1,5 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD schema_name 'public'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD table_name 'test_table'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv.sql new file mode 100644 index 000000000..7a91e09e9 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv.sql @@ -0,0 +1,20 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv_msql.sql new file mode 100644 index 000000000..2c6f1712d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_add_priv_msql.sql @@ -0,0 +1 @@ +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts.sql new file mode 100644 index 000000000..50d97ef55 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts.sql @@ -0,0 +1,19 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'test_public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts_msql.sql new file mode 100644 index 000000000..cdb8a27dd --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_col_opts_msql.sql @@ -0,0 +1,14 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP COLUMN col2; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 DROP NOT NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 TYPE integer; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 SET STATISTICS -1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (SET schema_name 'test_public'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns.sql new file mode 100644 index 000000000..8af1663d8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns.sql @@ -0,0 +1,15 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns_msql.sql new file mode 100644 index 000000000..9041626b6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_comment_add_columns_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col1 bigint NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col2 text NULL; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv.sql new file mode 100644 index 000000000..2365a797f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv.sql @@ -0,0 +1,17 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv_msql.sql new file mode 100644 index 000000000..56653c630 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/alter_remove_opts_priv_msql.sql @@ -0,0 +1,4 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS ( DROP schema_name); + +REVOKE ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options.sql new file mode 100644 index 000000000..95ceb43c2 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options.sql @@ -0,0 +1,20 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options_msql.sql new file mode 100644 index 000000000..20b3da4e0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/create_foreign_table_with_all_options_msql.sql @@ -0,0 +1,14 @@ +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/test_foreign_table.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/test_foreign_table.json new file mode 100644 index 000000000..89021a09f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.2_plus/test_foreign_table.json @@ -0,0 +1,242 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create FDW for foreign table", + "endpoint": "NODE-foreign_data_wrapper.obj", + "sql_endpoint": "NODE-foreign_data_wrapper.sql_id", + "data": { + "name": "test_fdw_for_foreign_table", + "fdwacl": [], + "fdwoptions": [] + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create foreign server for foreign table", + "endpoint": "NODE-foreign_server.obj", + "sql_endpoint": "NODE-foreign_server.sql_id", + "data": { + "name":"test_fs_for_foreign_table" + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create Foreign Table with all options", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner":"enterprisedb", + "schema": "public", + "basensp":"public", + "description":"Test Comment", + "ftsrvname":"test_fs_for_foreign_table", + "columns":[{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }], + "ftoptions":[{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }], + "acl":[{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"w", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"x", + "privilege":true, + "with_grant":false + }] + }] + }, + "expected_sql_file": "create_foreign_table_with_all_options.sql", + "expected_msql_file": "create_foreign_table_with_all_options_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, + { + "type": "create", + "name": "Create Foreign Table", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "basensp": "public", + "ftsrvname": "test_fs_for_foreign_table", + "columns": [] + } + }, { + "type": "alter", + "name": "Alter Foreign Table comment and add columns", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "description":"Test Comment", + "columns": { + "added": [{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }] + } + }, + "expected_sql_file": "alter_comment_add_columns.sql", + "expected_msql_file": "alter_comment_add_columns_msql.sql" + },{ + "type": "alter", + "name": "Alter Foreign Table add options", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "added": [{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }] + } + }, + "expected_sql_file": "alter_add_opts.sql", + "expected_msql_file": "alter_add_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table add privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "added": [{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + } + }, + "expected_sql_file": "alter_add_priv.sql", + "expected_msql_file": "alter_add_priv_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table change option and column", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "changed": [{ + "option":"schema_name", + "value":"test_public" + }] + }, + "columns": { + "changed": [{ + "attname": "col1", + "attnum": 1, + "attoptions": null, + "collname": "", + "coloptions": [], + "datatype": "integer", + "fulltype": "bigint" + }], + "deleted": [{ + "attname":"col2", + "datatype":"text" + }] + } + }, + "expected_sql_file": "alter_col_opts.sql", + "expected_msql_file": "alter_col_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table remove option, privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "deleted": [{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + }, + "ftoptions": { + "deleted": [{ + "option":"schema_name", + "value":"public" + }] + } + }, + "expected_sql_file": "alter_remove_opts_priv.sql", + "expected_msql_file": "alter_remove_opts_priv_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, { + "type": "delete", + "name": "Drop foreign server", + "endpoint": "NODE-foreign_server.delete_id", + "data": { + "name": "test_fs_for_foreign_table" + } + }, { + "type": "delete", + "name": "Drop FDW", + "endpoint": "NODE-foreign_data_wrapper.delete_id", + "data": { + "name": "test_fdw_for_foreign_table" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts.sql new file mode 100644 index 000000000..465b166f2 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts.sql @@ -0,0 +1,19 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts_msql.sql new file mode 100644 index 000000000..1160cd6b3 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_cons_opts_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD schema_name 'public'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (ADD table_name 'test_table'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv.sql new file mode 100644 index 000000000..5e168cdcc --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv.sql @@ -0,0 +1,23 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv_msql.sql new file mode 100644 index 000000000..2c6f1712d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_add_priv_msql.sql @@ -0,0 +1 @@ +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts.sql new file mode 100644 index 000000000..74860b43c --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts.sql @@ -0,0 +1,22 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'test_public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT INSERT, SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts_msql.sql new file mode 100644 index 000000000..cdb8a27dd --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_col_opts_msql.sql @@ -0,0 +1,14 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP COLUMN col2; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 DROP NOT NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 TYPE integer; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN col1 SET STATISTICS -1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS (SET schema_name 'test_public'); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns.sql new file mode 100644 index 000000000..8af1663d8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns.sql @@ -0,0 +1,15 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns_msql.sql new file mode 100644 index 000000000..9041626b6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_comment_add_columns_msql.sql @@ -0,0 +1,8 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col1 bigint NULL; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD COLUMN col2 text NULL; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons.sql new file mode 100644 index 000000000..2365a797f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons.sql @@ -0,0 +1,17 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 integer NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons_msql.sql new file mode 100644 index 000000000..007e93bc3 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/alter_remove_opts_priv_cons_msql.sql @@ -0,0 +1,7 @@ +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + DROP CONSTRAINT cons1; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OPTIONS ( DROP schema_name); + +REVOKE ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options.sql new file mode 100644 index 000000000..74e175ca4 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options.sql @@ -0,0 +1,23 @@ +-- FOREIGN TABLE: public."FT1_$%{}[]()&*^!@""'`\/#" + +-- DROP FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"; + +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL COLLATE pg_catalog."default" +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options_msql.sql new file mode 100644 index 000000000..dd1f25434 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/create_foreign_table_with_all_options_msql.sql @@ -0,0 +1,17 @@ +CREATE FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"( + col1 bigint NULL, + col2 text NULL +) + SERVER test_fs_for_foreign_table + OPTIONS (schema_name 'public', table_name 'test_table'); + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; + +ALTER FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + ADD CONSTRAINT cons1 CHECK (true) NO INHERIT; + +COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; + +GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/test_foreign_table.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/test_foreign_table.json new file mode 100644 index 000000000..675a544e4 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/ppas/9.5_plus/test_foreign_table.json @@ -0,0 +1,264 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create FDW for foreign table", + "endpoint": "NODE-foreign_data_wrapper.obj", + "sql_endpoint": "NODE-foreign_data_wrapper.sql_id", + "data": { + "name": "test_fdw_for_foreign_table", + "fdwacl": [], + "fdwoptions": [] + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create foreign server for foreign table", + "endpoint": "NODE-foreign_server.obj", + "sql_endpoint": "NODE-foreign_server.sql_id", + "data": { + "name":"test_fs_for_foreign_table" + }, + "store_object_id": "True" + }, { + "type": "create", + "name": "Create Foreign Table with all options", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner":"enterprisedb", + "schema": "public", + "basensp":"public", + "description":"Test Comment", + "ftsrvname":"test_fs_for_foreign_table", + "columns":[{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }], + "constraints":[{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }], + "ftoptions":[{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }], + "acl":[{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"w", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"x", + "privilege":true, + "with_grant":false + }] + }] + }, + "expected_sql_file": "create_foreign_table_with_all_options.sql", + "expected_msql_file": "create_foreign_table_with_all_options_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, + { + "type": "create", + "name": "Create Foreign Table", + "endpoint": "NODE-foreign_table.obj", + "sql_endpoint": "NODE-foreign_table.sql_id", + "data": { + "name": "FT1_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "basensp": "public", + "ftsrvname": "test_fs_for_foreign_table", + "columns": [] + } + }, { + "type": "alter", + "name": "Alter Foreign Table comment and add columns", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "description":"Test Comment", + "columns": { + "added": [{ + "attname":"col1", + "datatype":"bigint", + "coloptions":[] + },{ + "attname":"col2", + "datatype":"text", + "coloptions":[] + }] + } + }, + "expected_sql_file": "alter_comment_add_columns.sql", + "expected_msql_file": "alter_comment_add_columns_msql.sql" + },{ + "type": "alter", + "name": "Alter Foreign Table add constraints and options", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "constraints": { + "added": [{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }] + }, + "ftoptions": { + "added": [{ + "option":"schema_name", + "value":"public" + },{ + "option":"table_name", + "value":"test_table" + }] + } + }, + "expected_sql_file": "alter_add_cons_opts.sql", + "expected_msql_file": "alter_add_cons_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table add privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "added": [{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + } + }, + "expected_sql_file": "alter_add_priv.sql", + "expected_msql_file": "alter_add_priv_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table change option and column", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "ftoptions": { + "changed": [{ + "option":"schema_name", + "value":"test_public" + }] + }, + "columns": { + "changed": [{ + "attname": "col1", + "attnum": 1, + "attoptions": null, + "collname": "", + "coloptions": [], + "datatype": "integer", + "fulltype": "bigint" + }], + "deleted": [{ + "attname":"col2", + "datatype":"text" + }] + } + }, + "expected_sql_file": "alter_col_opts.sql", + "expected_msql_file": "alter_col_opts_msql.sql" + }, { + "type": "alter", + "name": "Alter Foreign Table remove option, constraint, privileges", + "endpoint": "NODE-foreign_table.obj_id", + "sql_endpoint": "NODE-foreign_table.sql_id", + "msql_endpoint": "NODE-foreign_table.msql_id", + "data": { + "acl":{ + "deleted": [{ + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[{ + "privilege_type":"a", + "privilege":true, + "with_grant":false + },{ + "privilege_type":"r", + "privilege":true, + "with_grant":false + }] + }] + }, + "constraints": { + "deleted": [{ + "conname":"cons1", + "consrc":"true", + "connoinherit":true, + "convalidated":true + }] + }, + "ftoptions": { + "deleted": [{ + "option":"schema_name", + "value":"public" + }] + } + }, + "expected_sql_file": "alter_remove_opts_priv_cons.sql", + "expected_msql_file": "alter_remove_opts_priv_cons_msql.sql" + }, { + "type": "delete", + "name": "Drop foreign table", + "endpoint": "NODE-foreign_table.delete_id" + }, { + "type": "delete", + "name": "Drop foreign server", + "endpoint": "NODE-foreign_server.delete_id", + "data": { + "name": "test_fs_for_foreign_table" + } + }, { + "type": "delete", + "name": "Drop FDW", + "endpoint": "NODE-foreign_data_wrapper.delete_id", + "data": { + "name": "test_fdw_for_foreign_table" + } + } + ] +}