From 0f86b78d875b3b972f29c7d029b5a93a922a5b86 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Wed, 2 Aug 2023 11:26:09 +0530 Subject: [PATCH] Added support for PostgreSQL and EPAS 16 to ensure it works without any errors. #6588 --- docs/en_US/release_notes_7_6.rst | 4 + .../views/tests/pg/16_plus/alter_view.sql | 19 ++ .../pg/16_plus/alter_view_add_some_priv.sql | 20 ++ .../pg/16_plus/alter_view_definition.sql | 19 ++ .../pg/16_plus/alter_view_delete_priv.sql | 18 ++ .../pg/16_plus/alter_view_update_priv.sql | 20 ++ .../views/tests/pg/16_plus/create_view.sql | 17 ++ .../views/tests/pg/16_plus/test_mview.json | 259 ++++++++++++++++++ .../schemas/views/tests/pg/16_plus/tests.json | 225 +++++++++++++++ .../views/tests/ppas/16_plus/alter_view.sql | 19 ++ .../ppas/16_plus/alter_view_add_some_priv.sql | 20 ++ .../ppas/16_plus/alter_view_definition.sql | 15 + .../ppas/16_plus/alter_view_delete_priv.sql | 17 ++ .../ppas/16_plus/alter_view_update_priv.sql | 20 ++ .../views/tests/ppas/16_plus/create_view.sql | 17 ++ .../views/tests/ppas/16_plus/test_mview.json | 259 ++++++++++++++++++ .../views/tests/ppas/16_plus/tests.json | 207 ++++++++++++++ .../schemas/views/tests/test_views_get.py | 15 + .../schemas/views/tests/view_test_data.json | 30 +- .../databases/sql/16_plus/get_ctypes.sql | 8 + .../databases/sql/16_plus/properties.sql | 40 +++ .../tests/test_backup_create_job_unit_test.py | 160 ++++++++++- .../backup/tests/test_create_backup_job.py | 50 +++- .../restore/tests/test_create_restore_job.py | 67 ++++- 24 files changed, 1514 insertions(+), 31 deletions(-) create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_add_some_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_definition.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_delete_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_update_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/create_view.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/test_mview.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/tests.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_add_some_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_definition.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_delete_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_update_priv.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/create_view.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/test_mview.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/tests.json create mode 100644 web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql create mode 100644 web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/properties.sql diff --git a/docs/en_US/release_notes_7_6.rst b/docs/en_US/release_notes_7_6.rst index abb3a376a..24510bb71 100644 --- a/docs/en_US/release_notes_7_6.rst +++ b/docs/en_US/release_notes_7_6.rst @@ -20,6 +20,8 @@ Bundled PostgreSQL Utilities New features ************ + | `Issue #2595 `_ - Added Expression to CREATE INDEX. + | `Issue #6375 `_ - Added support for ALTER INDEX column statistics. | `Issue #6376 `_ - Added unlogged option while creating a sequence. | `Issue #6381 `_ - Added support for SYSTEM, CONCURRENTLY and TABLESPACE options in REINDEX. | `Issue #6397 `_ - Added new/missing options to the VACUUM command. @@ -28,8 +30,10 @@ New features Housekeeping ************ + | `Issue #6588 `_ - Added support for PostgreSQL and EPAS 16 to ensure it works without any errors. Bug fixes ********* | `Issue #6500 `_ - Fix the issue where query tool window turns blank if the user tries to generate a graph on the result. + | `Issue #6624 `_ - Fix an issue where changing MFA_SUPPORTED_METHODS breaks the MFA validation. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view.sql new file mode 100644 index 000000000..f457970c8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view.sql @@ -0,0 +1,19 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_add_some_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_add_some_priv.sql new file mode 100644 index 000000000..d082512d2 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_add_some_priv.sql @@ -0,0 +1,20 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT SELECT ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO PUBLIC; +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_definition.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_definition.sql new file mode 100644 index 000000000..f457970c8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_definition.sql @@ -0,0 +1,19 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_delete_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_delete_priv.sql new file mode 100644 index 000000000..71259e42f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_delete_priv.sql @@ -0,0 +1,18 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_update_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_update_priv.sql new file mode 100644 index 000000000..8b5aa69b5 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/alter_view_update_priv.sql @@ -0,0 +1,20 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT SELECT ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/create_view.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/create_view.sql new file mode 100644 index 000000000..b5806dcc0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/create_view.sql @@ -0,0 +1,17 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=local +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO postgres; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO postgres; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/test_mview.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/test_mview.json new file mode 100644 index 000000000..1feb2d1a5 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/test_mview.json @@ -0,0 +1,259 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Materialised Views", + "endpoint": "NODE-mview.obj", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql", + "data": { + "spcname": "pg_default", + "schema": "public", + "owner": "postgres", + "datacl": [], + "seclabels": [], + "name": "testmview_$%{}[]()&*^!/@`#", + "comment": "comment1", + "definition": "SELECT 1 AS col1" + }, + "expected_sql_file": "create_mview.sql", + "expected_msql_file": "create_mview_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Adding privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "added": [ + { + "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview.sql", + "expected_msql_file": "alter_mview_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Remove all privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "deleted": [ + { + "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview_drop_all_priv.sql", + "expected_msql_file": "alter_mview_drop_all_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (change grantee in privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "changed": [ + { + "grantee": "PUBLIC", + "grantor": "postgres", + "old_grantee": "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview_change_grantee_priv.sql", + "expected_msql_file": "alter_mview_change_grantee_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (change definition)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "definition": "SELECT 12 AS col1;" + }, + "expected_sql_file": "alter_mview_definition.sql", + "expected_msql_file": "alter_mview_definition_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Fillfactor)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "fillfactor": "18", + "with_data": true + }, + "expected_sql_file": "alter_mview_add_fillfactor.sql", + "expected_msql_file": "alter_mview_add_fillfactor_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (add table parameters)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "autovacuum_custom": true, + "autovacuum_enabled": "t", + "vacuum_table": { + "changed": [ + { + "name": "autovacuum_analyze_scale_factor", + "value": 0.2 + } + ] + } + }, + "expected_sql_file": "alter_mview_add_table_parameter.sql", + "expected_msql_file": "alter_mview_add_table_parameter_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (remove table parameters)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "autovacuum_custom": true, + "autovacuum_enabled": "x", + "vacuum_table": { + "changed": [ + { + "name": "autovacuum_analyze_scale_factor", + "value": null + } + ] + } + }, + "expected_sql_file": "alter_mview_remove_table_parameter.sql", + "expected_msql_file": "alter_mview_remove_table_parameter_msql.sql" + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/tests.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/tests.json new file mode 100644 index 000000000..aae4702db --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/16_plus/tests.json @@ -0,0 +1,225 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Table for Views", + "endpoint": "NODE-table.obj", + "sql_endpoint": "NODE-table.sql_id", + "data": { + "name": "test_view_table", + "check_constraint": [], + "coll_inherits": "[]", + "columns": [ + { + "name": "col1", + "cltype": "integer" + } + ], + "schema": "public" + } + }, + { + "type": "create", + "name": "Create View", + "endpoint": "NODE-view.obj", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql", + "data": { + "definition": "select col1 from test_view_table;", + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "local", + "security_barrier": false, + "security_invoker": false, + "comment":"Testcomment", + "datacl":[{"grantee":"postgres", "old_grantee": "postgres", "grantor":"postgres", "privileges":[{"privilege_type": "a", "privilege": true, + "with_grant":false}]}] + }, + "expected_sql_file": "create_view.sql", + "expected_msql_file": "create_view_msql.sql" + }, + { + "type": "alter", + "name": "Alter View", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "security_invoker": true, + "comment":"Testcomment-updated", + "datacl":[{"grantee":"postgres", "grantor":"postgres", "old_grantee": "postgres", "privileges":[{"privilege_type": "a", "privilege": true, + "with_grant":false}]}] + }, + "expected_sql_file": "alter_view.sql", + "expected_msql_file": "alter_view_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (changing code)", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "definition": "SELECT * FROM test_view_table;" + }, + "expected_sql_file": "alter_view_definition.sql", + "expected_msql_file": "alter_view_definition_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (adding privileges)", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl":{ + "added":[ + { + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_add_some_priv.sql", + "expected_msql_file": "alter_view_add_some_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (deleting privileges (PUBLIC))", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "deleted":[ + { + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + } + }, + { + "type": "alter", + "name": "Alter View (changing privileges (postgres to PUBLIC))", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "changed":[ + { + "grantee":"PUBLIC", + "grantor":"postgres", + "old_grantee": "postgres", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_update_priv.sql", + "expected_msql_file": "alter_view_update_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (deleting privileges)", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "deleted":[ + { + "grantee":"PUBLIC", + "grantor":"postgres", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_delete_priv.sql", + "expected_msql_file": "alter_view_delete_priv_msql.sql" + }, + { + "type": "delete", + "name": "Drop View", + "endpoint": "NODE-view.obj_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "postgres", + "schema": "public" + } + }, + { + "type": "delete", + "name": "Drop Table for view", + "endpoint": "NODE-table.obj_id", + "data": { + "name": "test_view_table", + "owner": "postgres", + "schema": "public" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view.sql new file mode 100644 index 000000000..10c32ec2b --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view.sql @@ -0,0 +1,19 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE IF EXISTS public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_add_some_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_add_some_priv.sql new file mode 100644 index 000000000..95afdf039 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_add_some_priv.sql @@ -0,0 +1,20 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE IF EXISTS public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT SELECT ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO PUBLIC; +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_definition.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_definition.sql new file mode 100644 index 000000000..e29d48637 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_definition.sql @@ -0,0 +1,15 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" + AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_delete_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_delete_priv.sql new file mode 100644 index 000000000..1efa4950b --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_delete_priv.sql @@ -0,0 +1,17 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE IF EXISTS public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_update_priv.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_update_priv.sql new file mode 100644 index 000000000..e25bf89ae --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/alter_view_update_priv.sql @@ -0,0 +1,20 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=cascaded, + security_barrier=true, + security_invoker=true +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE IF EXISTS public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment-updated'; + +GRANT SELECT ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO PUBLIC; + diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/create_view.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/create_view.sql new file mode 100644 index 000000000..9f8e731f6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/create_view.sql @@ -0,0 +1,17 @@ +-- View: public.testview_$%{}[]()&*^!@"'`\/# + +-- DROP VIEW public."testview_$%{}[]()&*^!@""'`\/#"; + +CREATE OR REPLACE VIEW public."testview_$%{}[]()&*^!@""'`\/#" +WITH ( + check_option=local +) AS + SELECT col1 + FROM test_view_table; + +ALTER TABLE IF EXISTS public."testview_$%{}[]()&*^!@""'`\/#" + OWNER TO enterprisedb; +COMMENT ON VIEW public."testview_$%{}[]()&*^!@""'`\/#" + IS 'Testcomment'; + +GRANT ALL ON TABLE public."testview_$%{}[]()&*^!@""'`\/#" TO enterprisedb; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/test_mview.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/test_mview.json new file mode 100644 index 000000000..aacf62106 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/test_mview.json @@ -0,0 +1,259 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Materialised Views", + "endpoint": "NODE-mview.obj", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql", + "data": { + "spcname": "pg_default", + "schema": "public", + "owner": "enterprisedb", + "datacl": [], + "seclabels": [], + "name": "testmview_$%{}[]()&*^!/@`#", + "comment": "comment1", + "definition": "SELECT 1 AS col1" + }, + "expected_sql_file": "create_mview.sql", + "expected_msql_file": "create_mview_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Adding privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "added": [ + { + "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview.sql", + "expected_msql_file": "alter_mview_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Remove all privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "deleted": [ + { + "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview_drop_all_priv.sql", + "expected_msql_file": "alter_mview_drop_all_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (change grantee in privileges)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "datacl": { + "changed": [ + { + "grantee": "PUBLIC", + "grantor": "enterprisedb", + "old_grantee": "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": "d", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "D", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "x", + "privilege": true, + "with_grant": false + }, + { + "privilege_type": "t", + "privilege": true, + "with_grant": false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_mview_change_grantee_priv.sql", + "expected_msql_file": "alter_mview_change_grantee_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (change definition)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "definition": "SELECT 12 AS col1;" + }, + "expected_sql_file": "alter_mview_definition.sql", + "expected_msql_file": "alter_mview_definition_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (Fillfactor)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "fillfactor": "18", + "with_data": true + }, + "expected_sql_file": "alter_mview_add_fillfactor.sql", + "expected_msql_file": "alter_mview_add_fillfactor_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (add table parameters)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "autovacuum_custom": true, + "autovacuum_enabled": "t", + "vacuum_table": { + "changed": [ + { + "name": "autovacuum_analyze_scale_factor", + "value": 0.2 + } + ] + } + }, + "expected_sql_file": "alter_mview_add_table_parameter.sql", + "expected_msql_file": "alter_mview_add_table_parameter_msql.sql" + }, + { + "type": "alter", + "name": "Alter Materialised Views (remove table parameters)", + "endpoint": "NODE-mview.obj_id", + "sql_endpoint": "NODE-mview.sql_id", + "msql_endpoint": "NODE-mview.msql_id", + "data": { + "autovacuum_custom": true, + "autovacuum_enabled": "x", + "vacuum_table": { + "changed": [ + { + "name": "autovacuum_analyze_scale_factor", + "value": null + } + ] + } + }, + "expected_sql_file": "alter_mview_remove_table_parameter.sql", + "expected_msql_file": "alter_mview_remove_table_parameter_msql.sql" + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/tests.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/tests.json new file mode 100644 index 000000000..c8111f9f5 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/16_plus/tests.json @@ -0,0 +1,207 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Table for Views", + "endpoint": "NODE-table.obj", + "sql_endpoint": "NODE-table.sql_id", + "data": { + "name": "test_view_table", + "check_constraint": [], + "coll_inherits": "[]", + "columns": [ + { + "name": "col1", + "cltype": "integer" + } + ], + "schema": "public" + } + }, + { + "type": "create", + "name": "Create View", + "endpoint": "NODE-view.obj", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql", + "data": { + "definition": "select col1 from test_view_table;", + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "check_option": "local", + "security_barrier": false, + "security_invoker": false, + "comment":"Testcomment", + "datacl":[{"grantee":"enterprisedb", "grantor":"enterprisedb", "privileges":[{"privilege_type": "a", "privilege": true, + "with_grant":false}]}] + }, + "expected_sql_file": "create_view.sql", + "expected_msql_file": "create_view_msql.sql" + }, + { + "type": "alter", + "name": "Alter View", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "security_invoker": true, + "comment":"Testcomment-updated", + "datacl":[{"grantee":"enterprisedb", "grantor":"enterprisedb", "privileges":[{"privilege_type": "a", "privilege": true, + "with_grant":false}]}] + }, + "expected_sql_file": "alter_view.sql", + "expected_msql_file": "alter_view_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (adding privileges)", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "datacl":{ + "added":[ + { + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_add_some_priv.sql", + "expected_msql_file": "alter_view_add_some_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (deleting privileges (PUBLIC))", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "deleted":[ + { + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + } + }, + { + "type": "alter", + "name": "Alter View (changing privileges (enterprisedb to PUBLIC))", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "changed":[ + { + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "old_grantee": "enterprisedb", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_update_priv.sql", + "expected_msql_file": "alter_view_update_priv_msql.sql" + }, + { + "type": "alter", + "name": "Alter View (deleting privileges)", + "endpoint": "NODE-view.obj_id", + "sql_endpoint": "NODE-view.sql_id", + "msql_endpoint": "NODE-view.msql_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public", + "check_option": "cascaded", + "security_barrier": true, + "comment":"Testcomment-updated", + "datacl": + { + "deleted":[ + { + "grantee":"PUBLIC", + "grantor":"enterprisedb", + "privileges":[ + { + "privilege_type":"r", + "privilege":true, + "with_grant":false + } + ] + } + ] + } + }, + "expected_sql_file": "alter_view_delete_priv.sql", + "expected_msql_file": "alter_view_delete_priv_msql.sql" + }, + { + "type": "delete", + "name": "Drop View", + "endpoint": "NODE-view.obj_id", + "data": { + "name": "testview_$%{}[]()&*^!@\"'`\\/#", + "owner": "enterprisedb", + "schema": "public" + } + }, + { + "type": "delete", + "name": "Drop Table for view", + "endpoint": "NODE-table.obj_id", + "data": { + "name": "test_view_table", + "owner": "enterprisedb", + "schema": "public" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py index 87db75c9d..55f601a5a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py @@ -43,6 +43,21 @@ class ViewsGetTestCase(BaseTestGenerator): if not db_con['data']["connected"]: raise Exception("Could not connect to database to fetch the view.") + # Check DB version + if "server_min_version" in self.data: + server_con = server_utils.connect_server(self, self.server_id) + if server_con["info"] != "Server connected.": + raise Exception("Could not connect to server to check version") + if server_con["data"]["version"] < self.data["server_min_version"]: + self.skipTest(self.data["skip_msg"]) + + if "server_max_version" in self.data: + server_con = server_utils.connect_server(self, self.server_id) + if server_con["info"] != "Server connected.": + raise Exception("Could not connect to server to check version") + if server_con["data"]["version"] > self.data["server_max_version"]: + self.skipTest(self.data["skip_msg"]) + # Create schema self.schema_id = schema_info["schema_id"] self.schema_name = schema_info["schema_name"] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/view_test_data.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/view_test_data.json index a42a66bdb..2a8663c01 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/view_test_data.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/view_test_data.json @@ -152,13 +152,16 @@ "is_list": false }, { - "name": "Get view: With existing view having brackets.", + "name": "Get view: With existing view having brackets (=16).", + "url": "/browser/view/obj/", + "is_positive_test": true, + "inventory_data": { + "query": "\"CREATE OR REPLACE VIEW %s.%s AS SELECT CASE WHEN (pg_db.datistemplate = false AND pg_db.datallowconn = true AND (pg_db.datconnlimit = -1 OR pg_db.datacl is null)) then true else false end as res FROM pg_database pg_db; ALTER TABLE %s.%s OWNER TO %s\" % (schema_name, view_name, schema_name, view_name, server['username'])" + }, + "test_data": { + "server_min_version": 160000, + "skip_msg": "Definition is different from v16 onwards." + }, + "mocking_required": false, + "mock_data": {}, + "expected_data": { + "status_code": 200, + "error_msg": null, + "test_result_data": { + "definition": " SELECT\n CASE\n WHEN ((datistemplate = false) AND (datallowconn = true) AND ((datconnlimit = '-1'::integer) OR (datacl IS NULL))) THEN true\n ELSE false\n END AS res\n FROM pg_database pg_db;", + "pg_definition": " SELECT\n CASE\n WHEN datistemplate = false AND datallowconn = true AND (datconnlimit = '-1'::integer OR datacl IS NULL) THEN true\n ELSE false\n END AS res\n FROM pg_database pg_db;" + } + }, + "is_list": false + }, { "name": "Get views list: With existing views.", "url": "/browser/view/obj/", diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql new file mode 100644 index 000000000..4dfd31e37 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql @@ -0,0 +1,8 @@ +SELECT CASE WHEN datlocprovider = 'i' THEN + (SELECT daticulocale as cname FROM pg_database WHERE datname = current_database()) +ELSE + (SELECT datcollate as cname FROM pg_database WHERE datname = current_database() + UNION + SELECT datctype as cname FROM pg_database WHERE datname = current_database()) +END +FROM pg_database WHERE datname = current_database(); diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/properties.sql new file mode 100644 index 000000000..9e1ad6abc --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/properties.sql @@ -0,0 +1,40 @@ +SELECT + db.oid AS did, db.oid, db.datname AS name, db.dattablespace AS spcoid, + spcname, datallowconn, pg_catalog.pg_encoding_to_char(encoding) AS encoding, + pg_catalog.pg_get_userbyid(datdba) AS datowner, db.datcollate, db.datctype, + datconnlimit, + pg_catalog.has_database_privilege(db.oid, 'CREATE') AS cancreate, + pg_catalog.current_setting('default_tablespace') AS default_tablespace, + descr.description AS comments, db.datistemplate AS is_template, + {### Default ACL for Tables ###} + '' AS tblacl, + {### Default ACL for Sequnces ###} + '' AS seqacl, + {### Default ACL for Functions ###} + '' AS funcacl, + pg_catalog.array_to_string(datacl::text[], ', ') AS acl +FROM pg_catalog.pg_database db + LEFT OUTER JOIN pg_catalog.pg_tablespace ta ON db.dattablespace=ta.OID + LEFT OUTER JOIN pg_catalog.pg_shdescription descr ON ( + db.oid=descr.objoid AND descr.classoid='pg_database'::regclass + ) +WHERE +{% if show_user_defined_templates is defined %} + db.datistemplate = {{show_user_defined_templates}} AND +{% endif %} +{% if did %} + db.oid = {{ did|qtLiteral(conn) }}::OID +{% else %} + {% if name %} + db.datname = {{ name|qtLiteral(conn) }}::text + {% endif %} +{% endif %} + +{% if db_restrictions %} + {% if did or name %}AND{% endif %} + db.datname in ({{db_restrictions}}) +{% elif not did and not name%} + db.oid > {{ last_system_oid }}::OID OR db.datname IN ('postgres', 'edb') +{% endif %} + +ORDER BY datname; diff --git a/web/pgadmin/tools/backup/tests/test_backup_create_job_unit_test.py b/web/pgadmin/tools/backup/tests/test_backup_create_job_unit_test.py index bfb2e8da1..73f0e7dfe 100644 --- a/web/pgadmin/tools/backup/tests/test_backup_create_job_unit_test.py +++ b/web/pgadmin/tools/backup/tests/test_backup_create_job_unit_test.py @@ -24,6 +24,7 @@ VERBOSE = '--verbose' FORMAT_C = '--format=c' FORMAT_P = '--format=p' BLOBS = '--blobs' +LARGE_OBJECTS = '--large-objects' DATA_ONLY = '--data-only' SCHEMA_ONLY = '--schema-only' @@ -31,7 +32,7 @@ SCHEMA_ONLY = '--schema-only' class BackupCreateJobTest(BaseTestGenerator): """Test the BackupCreateJob class""" scenarios = [ - ('When backup object with default options', + ('When backup object with default options (< v16)', dict( class_params=dict( sid=1, @@ -54,7 +55,38 @@ class BackupCreateJobTest(BaseTestGenerator): url=BACKUP_OBJECT_URL, expected_cmd_opts=[VERBOSE, FORMAT_C, BLOBS], not_expected_cmd_opts=[], - expected_exit_code=[0, None] + expected_exit_code=[0, None], + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' + )), + ('When backup object with default options (>= v16)', + dict( + class_params=dict( + sid=1, + name='test_backup_server', + port=5444, + host='localhost', + database='postgres', + bfile='test_backup', + username='postgres' + ), + params=dict( + file='test_backup_file', + format='custom', + verbose=True, + blobs=True, + schemas=[], + tables=[], + database='postgres' + ), + url=BACKUP_OBJECT_URL, + expected_cmd_opts=[VERBOSE, FORMAT_C, LARGE_OBJECTS], + not_expected_cmd_opts=[], + expected_exit_code=[0, None], + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' )), ('When backup object with format directory', dict( @@ -616,7 +648,7 @@ class BackupCreateJobTest(BaseTestGenerator): not_expected_cmd_opts=[], expected_exit_code=[0, None] )), - ('When backup the object with format tar', + ('When backup the object with format tar (< v16)', dict( class_params=dict( sid=1, @@ -641,9 +673,42 @@ class BackupCreateJobTest(BaseTestGenerator): BLOBS, '--format=t'], not_expected_cmd_opts=[], - expected_exit_code=[0, None] + expected_exit_code=[0, None], + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' )), - ('When backup a schema with default options', + ('When backup the object with format tar (>= v16)', + dict( + class_params=dict( + sid=1, + name='test_backup_server', + port=5444, + host='localhost', + database='postgres', + bfile='test_backup', + username='postgres' + ), + params=dict( + file='test_backup_file', + format='tar', + verbose=True, + schemas=[], + tables=[], + database='postgres', + blobs=True, + ), + url=BACKUP_OBJECT_URL, + expected_cmd_opts=[VERBOSE, + LARGE_OBJECTS, + '--format=t'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None], + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' + )), + ('When backup a schema with default options (< v16)', dict( class_params=dict( sid=1, @@ -667,9 +732,41 @@ class BackupCreateJobTest(BaseTestGenerator): expected_cmd_opts=[VERBOSE, FORMAT_C, BLOBS, '--schema', 'schema1'], not_expected_cmd_opts=[], - expected_exit_code=[0, None] + expected_exit_code=[0, None], + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' )), - ('When backup a table with default options', + ('When backup a schema with default options (>=v16)', + dict( + class_params=dict( + sid=1, + name='test_backup_server', + port=5444, + host='localhost', + database='postgres', + bfile='test_backup', + username='postgres' + ), + params=dict( + file='test_backup_file', + format='custom', + verbose=True, + blobs=True, + schemas=['schema1'], + tables=[], + database='postgres' + ), + url=BACKUP_OBJECT_URL, + expected_cmd_opts=[VERBOSE, FORMAT_C, LARGE_OBJECTS, + '--schema', 'schema1'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None], + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' + )), + ('When backup a table with default options (< v16)', dict( class_params=dict( sid=1, @@ -693,7 +790,39 @@ class BackupCreateJobTest(BaseTestGenerator): expected_cmd_opts=[VERBOSE, FORMAT_C, BLOBS, '--table', 'public.table1'], not_expected_cmd_opts=[], - expected_exit_code=[0, None] + expected_exit_code=[0, None], + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' + )), + ('When backup a table with default options (>= v16)', + dict( + class_params=dict( + sid=1, + name='test_backup_server', + port=5444, + host='localhost', + database='postgres', + bfile='test_backup', + username='postgres' + ), + params=dict( + file='test_backup_file', + format='custom', + verbose=True, + blobs=True, + schemas=[], + tables=[['public', 'table1']], + database='postgres' + ), + url=BACKUP_OBJECT_URL, + expected_cmd_opts=[VERBOSE, FORMAT_C, LARGE_OBJECTS, + '--table', 'public.table1'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None], + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' )), ('When backup the server', dict( @@ -1153,6 +1282,16 @@ class BackupCreateJobTest(BaseTestGenerator): ] def setUp(self): + if hasattr(self, 'server_min_version') and \ + self.server_information['server_version'] < \ + self.server_min_version: + self.skipTest(self.message) + + if hasattr(self, 'server_max_version') and \ + self.server_information['server_version'] > \ + self.server_max_version: + self.skipTest(self.message) + if 'default_binary_paths' not in self.server or \ self.server['default_binary_paths'] is None or \ self.server['type'] not in self.server['default_binary_paths'] or \ @@ -1222,11 +1361,6 @@ class BackupCreateJobTest(BaseTestGenerator): db_owner = server_response['data']['user']['name'] self.data = database_utils.get_db_data(db_owner) - if hasattr(self, 'server_min_version') and \ - server_response["data"]["version"] < \ - self.server_min_version: - self.skipTest(self.message) - url = self.url.format(self.server_id) # Create the backup job diff --git a/web/pgadmin/tools/backup/tests/test_create_backup_job.py b/web/pgadmin/tools/backup/tests/test_create_backup_job.py index 3862e46ac..150d784d6 100644 --- a/web/pgadmin/tools/backup/tests/test_create_backup_job.py +++ b/web/pgadmin/tools/backup/tests/test_create_backup_job.py @@ -18,7 +18,7 @@ import pgadmin.tools.backup.tests.test_backup_utils as backup_utils class BackupJobTest(BaseTestGenerator): """Backup api test cases""" scenarios = [ - ('When backup the object with the default options', + ('When backup the object with the default options (< v16)', dict( params=dict( file='test_backup', @@ -34,11 +34,46 @@ class BackupJobTest(BaseTestGenerator): expected_cmd_opts=['--verbose', '--format=c', '--blobs'], not_expected_cmd_opts=[], expected_exit_code=[0, None] - ) + ), + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' + )), + ('When backup the object with the default options (>= v16)', + dict( + params=dict( + file='test_backup', + format='custom', + verbose=True, + blobs=True, + schemas=[], + tables=[], + database='postgres' + ), + url='/backup/job/{0}/object', + expected_params=dict( + expected_cmd_opts=['--verbose', '--format=c', + '--large-objects'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None] + ), + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' )) ] def setUp(self): + if hasattr(self, 'server_min_version') and \ + self.server_information['server_version'] < \ + self.server_min_version: + self.skipTest(self.message) + + if hasattr(self, 'server_max_version') and \ + self.server_information['server_version'] > \ + self.server_max_version: + self.skipTest(self.message) + if 'default_binary_paths' not in self.server or \ self.server['default_binary_paths'] is None or \ self.server['type'] not in self.server['default_binary_paths'] or\ @@ -56,9 +91,9 @@ class BackupJobTest(BaseTestGenerator): if os.name == 'nt': binary_path = binary_path + '.exe' - retVal = does_utility_exist(binary_path) - if retVal is not None: - self.skipTest(retVal) + ret_val = does_utility_exist(binary_path) + if ret_val is not None: + self.skipTest(ret_val) def runTest(self): self.server_id = parent_node_dict["server"][-1]["server_id"] @@ -75,6 +110,5 @@ class BackupJobTest(BaseTestGenerator): self.assertEqual ) - if backup_file is not None: - if os.path.isfile(backup_file): - os.remove(backup_file) + if backup_file is not None and os.path.isfile(backup_file): + os.remove(backup_file) diff --git a/web/pgadmin/tools/restore/tests/test_create_restore_job.py b/web/pgadmin/tools/restore/tests/test_create_restore_job.py index f98c2d595..62705d7da 100644 --- a/web/pgadmin/tools/restore/tests/test_create_restore_job.py +++ b/web/pgadmin/tools/restore/tests/test_create_restore_job.py @@ -23,7 +23,7 @@ import pgadmin.tools.backup.tests.test_backup_utils as backup_utils class RestoreJobTest(BaseTestGenerator): """Backup api test cases""" scenarios = [ - ('When restore the object with the default options', + ('When restore the object with the default options (< v16)', dict( params=dict( file='test_restore_file', @@ -56,11 +56,63 @@ class RestoreJobTest(BaseTestGenerator): expected_exit_code=[0, None] ) - ) + ), + server_max_version=159999, + message='--blobs is deprecated and is not supported by EPAS/PG ' + 'server greater than 15' + )), + ('When restore the object with the default options (>= v16)', + dict( + params=dict( + file='test_restore_file', + format='custom', + custom=False, + verbose=True, + blobs=True, + schemas=[], + tables=[], + database='test_restore_database' + ), + url='/restore/job/{0}', + expected_cmd_opts=['--verbose'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None], + backup_options=dict( + params=dict( + file='test_restore_file', + format='custom', + verbose=True, + blobs=True, + schemas=[], + tables=[], + database='test_restore_database' + ), + url='/backup/job/{0}/object', + expected_params=dict( + expected_cmd_opts=['--verbose', '--format=c', + '--large-objects'], + not_expected_cmd_opts=[], + expected_exit_code=[0, None] + ) + + ), + server_min_version=160000, + message='--large-objects is not supported by EPAS/PG server ' + 'less than 16' )) ] def setUp(self): + if hasattr(self, 'server_min_version') and \ + self.server_information['server_version'] < \ + self.server_min_version: + self.skipTest(self.message) + + if hasattr(self, 'server_max_version') and \ + self.server_information['server_version'] > \ + self.server_max_version: + self.skipTest(self.message) + if 'default_binary_paths' not in self.server or \ self.server['default_binary_paths'] is None or \ self.server['type'] not in self.server['default_binary_paths'] or\ @@ -78,9 +130,9 @@ class RestoreJobTest(BaseTestGenerator): if os.name == 'nt': binary_path = binary_path + '.exe' - retVal = does_utility_exist(binary_path) - if retVal is not None: - self.skipTest(retVal) + ret_val = does_utility_exist(binary_path) + if ret_val is not None: + self.skipTest(ret_val) def create_backup(self): url = self.backup_options['url'].format(self.server_id) @@ -187,9 +239,8 @@ class RestoreJobTest(BaseTestGenerator): self.assertEqual(restore_ack_res['success'], 1) - if self.backup_file is not None: - if os.path.isfile(self.backup_file): - os.remove(self.backup_file) + if self.backup_file is not None and os.path.isfile(self.backup_file): + os.remove(self.backup_file) @staticmethod def get_params(data):