diff --git a/docs/en_US/release_notes_4_11.rst b/docs/en_US/release_notes_4_11.rst index 9f9716d7e..748b2760a 100644 --- a/docs/en_US/release_notes_4_11.rst +++ b/docs/en_US/release_notes_4_11.rst @@ -25,6 +25,7 @@ Housekeeping | `Issue #4460 `_ - Add Reverse Engineered SQL tests for FTS Dictionaries. | `Issue #4463 `_ - Add Reverse Engineered SQL tests for Domains. | `Issue #4464 `_ - Add Reverse Engineered SQL tests for Collations. +| `Issue #4468 `_ - Add Reverse Engineered SQL tests for Types. Bug fixes ********* diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/types/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/types/sql/default/update.sql index 661ac9f11..bd589f378 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/types/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/types/sql/default/update.sql @@ -130,12 +130,12 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }} {% if 'changed' in data.typacl %} {% for priv in data.typacl.changed %} {{ PRIVILEGE.UNSETALL(conn, 'TYPE', priv.grantee, o_data.name, o_data.schema) }} -{{ PRIVILEGE.SET(conn, 'TYPE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.schema) }} +{{ PRIVILEGE.SET(conn, 'TYPE', priv.grantee, o_data.name, priv.without_grant, priv.with_grant, o_data.schema) }} {% endfor %} {% endif %} {% if 'added' in data.typacl %} {% for priv in data.typacl.added %} -{{ PRIVILEGE.SET(conn, 'TYPE', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.schema) }} +{{ PRIVILEGE.SET(conn, 'TYPE', priv.grantee, o_data.name, priv.without_grant, priv.with_grant, o_data.schema) }} {% endfor %} {% endif %} {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_acl_description.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_acl_description.sql new file mode 100644 index 000000000..eb5c7747b --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_acl_description.sql @@ -0,0 +1,20 @@ +-- Type: composite_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" AS +( + mname2 character varying(50) COLLATE pg_catalog."C", + mname3 text[] COLLATE pg_catalog."C", + mname4 bigint +); + +ALTER TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; + +COMMENT ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" + IS 'this is test'; + +GRANT USAGE ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" TO ; + +GRANT USAGE ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_add_member.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_add_member.sql new file mode 100644 index 000000000..b864240c0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_add_member.sql @@ -0,0 +1,14 @@ +-- Type: composite_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" AS +( + mname1 bigint, + mname2 character varying(50) COLLATE pg_catalog."C", + mname3 text[] COLLATE pg_catalog."C", + mname4 bigint +); + +ALTER TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_remove_member.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_remove_member.sql new file mode 100644 index 000000000..013245dac --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_composite_type_remove_member.sql @@ -0,0 +1,13 @@ +-- Type: composite_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" AS +( + mname2 character varying(50) COLLATE pg_catalog."C", + mname3 text[] COLLATE pg_catalog."C", + mname4 bigint +); + +ALTER TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_acl_description.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_acl_description.sql new file mode 100644 index 000000000..fd619221e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_acl_description.sql @@ -0,0 +1,16 @@ +-- Type: enum_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."enum_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" AS ENUM + ('a', 'b', 'c', 'd'); + +ALTER TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; + +COMMENT ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" + IS 'this is test'; + +GRANT USAGE ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" TO ; + +GRANT USAGE ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_label.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_label.sql new file mode 100644 index 000000000..1a7a15307 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_enum_type_label.sql @@ -0,0 +1,9 @@ +-- Type: enum_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."enum_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" AS ENUM + ('a', 'b', 'c', 'd'); + +ALTER TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_range_type_acl_description.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_range_type_acl_description.sql new file mode 100644 index 000000000..8f3d3f62c --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_range_type_acl_description.sql @@ -0,0 +1,19 @@ +-- Type: range_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."range_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."range_type_$%{}[]()&*^!@""'`\/#" AS RANGE +( + SUBTYPE=bool, + SUBTYPE_OPCLASS = bool_ops +); + +ALTER TYPE public."range_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; + +COMMENT ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#" + IS 'this is test'; + +GRANT USAGE ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#" TO ; + +GRANT USAGE ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_shell_type_acl_description.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_shell_type_acl_description.sql new file mode 100644 index 000000000..3f78bfd29 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/alter_shell_type_acl_description.sql @@ -0,0 +1,11 @@ +-- Type: shell_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"; + +ALTER TYPE public."shell_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; + +COMMENT ON TYPE public."shell_type_$%{}[]()&*^!@""'`\/#" + IS 'this is test'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type.sql new file mode 100644 index 000000000..d48f7053d --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type.sql @@ -0,0 +1,13 @@ +-- Type: composite_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" AS +( + mname1 bigint, + mname2 character varying(50) COLLATE pg_catalog."C", + mname3 text[] COLLATE pg_catalog."C" +); + +ALTER TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_enum_type.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_enum_type.sql new file mode 100644 index 000000000..ebccea875 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_enum_type.sql @@ -0,0 +1,9 @@ +-- Type: enum_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."enum_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" AS ENUM + ('a', 'b', 'c'); + +ALTER TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_range_type.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_range_type.sql new file mode 100644 index 000000000..be9c1a752 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_range_type.sql @@ -0,0 +1,12 @@ +-- Type: range_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."range_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."range_type_$%{}[]()&*^!@""'`\/#" AS RANGE +( + SUBTYPE=bool, + SUBTYPE_OPCLASS = bool_ops +); + +ALTER TYPE public."range_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_shell_type.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_shell_type.sql new file mode 100644 index 000000000..126f2b7ff --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_shell_type.sql @@ -0,0 +1,8 @@ +-- Type: shell_type_$%{}[]()&*^!@"'`\/# + +-- DROP TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"; + +CREATE TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"; + +ALTER TYPE public."shell_type_$%{}[]()&*^!@""'`\/#" + OWNER TO ; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json new file mode 100644 index 000000000..caded7697 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json @@ -0,0 +1,185 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create ENUM type", + "endpoint": "NODE-type.obj", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "name": "enum_type_$%{}[]()&*^!@\"'`\\/#", + "is_sys_type":false, + "typtype":"e", + "schema":"public", + "composite":[], + "enum":[{"label":"a"},{"label":"b"},{"label":"c"}], + "typacl":[], + "seclabels":[], + "description":"" + }, + "expected_sql_file": "create_enum_type.sql" + }, + { + "type": "alter", + "name": "alter ENUM type and add new label", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "enum": {"added": [{"label": "d"}]} + }, + "expected_sql_file": "alter_enum_type_label.sql" + }, + { + "type": "alter", + "name": "alter ENUM type and add ACL, description", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "description":"this is test", + "typacl": {"added": [{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"U","privilege":true,"with_grant":false}]}]} + }, + "expected_sql_file": "alter_enum_type_acl_description.sql" + }, + { + "type": "delete", + "name": "Drop ENUM type", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": {} + }, + + + { + "type": "create", + "name": "Create Composite type", + "endpoint": "NODE-type.obj", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "name": "composite_type_$%{}[]()&*^!@\"'`\\/#", + "is_sys_type":false, + "typtype":"c", + "schema":"public", + "composite":[ + {"member_name":"mname1","type":"bigint","is_tlength":false,"is_precision":false}, + {"member_name":"mname2","type":"character varying","tlength":50,"is_tlength":true,"is_precision":false,"collation":"pg_catalog.\"C\"","min_val":1,"max_val":2147483647,"collspcname":""}, + {"member_name":"mname3","type":"text[]","is_tlength":false,"is_precision":false,"collation":"pg_catalog.\"C\"","collspcname":""} + ], + "typacl":[], + "seclabels":[], + "description":"" + }, + "expected_sql_file": "create_composite_type.sql" + }, + { + "type": "alter", + "name": "alter Composite type and add new label", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "composite": {"added": [{"member_name":"mname4","type":"bigint","is_tlength":false,"is_precision":false}]} + }, + "expected_sql_file": "alter_composite_type_add_member.sql" + }, + { + "type": "alter", + "name": "alter Composite type and delete label", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "composite": {"deleted":[{"attnum":1,"member_name":"mname1","type":"bigint","tlength":null,"is_tlength":false,"precision":null,"is_precision":false,"collation":"","cltype":"bigint","hasSqrBracket":false,"fulltype":"bigint"}]} + }, + "expected_sql_file": "alter_composite_type_remove_member.sql" + }, + { + "type": "alter", + "name": "alter Composite type and add ACL, description", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "description":"this is test", + "typacl": {"added": [{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"U","privilege":true,"with_grant":false}]}]} + }, + "expected_sql_file": "alter_composite_type_acl_description.sql" + }, + { + "type": "delete", + "name": "Drop Composite type", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": {} + }, + + + { + "type": "create", + "name": "Create SHELL type", + "endpoint": "NODE-type.obj", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "name": "shell_type_$%{}[]()&*^!@\"'`\\/#", + "is_sys_type":false, + "typtype":"p", + "schema":"public", + "composite":[], + "enum":[], + "typacl":[], + "seclabels":[] + }, + "expected_sql_file": "create_shell_type.sql" + }, + { + "type": "alter", + "name": "alter SHELL type and add description", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "description":"this is test" + }, + "expected_sql_file": "alter_shell_type_acl_description.sql" + }, + { + "type": "delete", + "name": "Drop SHELL type", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": {} + }, + + + { + "type": "create", + "name": "Create RANGE type", + "endpoint": "NODE-type.obj", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "name": "range_type_$%{}[]()&*^!@\"'`\\/#", + "is_sys_type":false, + "typtype":"r", + "schema":"public", + "composite":[], + "enum":[], + "typacl":[], + "seclabels":[], + "typname":"bool" + }, + "expected_sql_file": "create_range_type.sql" + }, + { + "type": "alter", + "name": "alter RANGE type and add ACL, description", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": { + "description":"this is test", + "typacl": {"added": [{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"U","privilege":true,"with_grant":false}]}]} + }, + "expected_sql_file": "alter_range_type_acl_description.sql" + }, + { + "type": "delete", + "name": "Drop RANGE type", + "endpoint": "NODE-type.obj_id", + "sql_endpoint": "NODE-type.sql_id", + "data": {} + } + ] +} diff --git a/web/regression/re_sql/tests/test_resql.py b/web/regression/re_sql/tests/test_resql.py index 6b87f0306..471571a50 100644 --- a/web/regression/re_sql/tests/test_resql.py +++ b/web/regression/re_sql/tests/test_resql.py @@ -104,7 +104,15 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator): complete_file_name = os.path.join(self.test_folder, filename) with open(complete_file_name) as jsonfp: - data = json.load(jsonfp) + try: + data = json.load(jsonfp) + except Exception as e: + print( + "Unable to read the json file: {0}".format( + complete_file_name)) + traceback.print_exc() + continue + for key, scenarios in data.items(): self.execute_test_case(scenarios)