Add Reverse Engineered SQL tests for Types. Fixes #4468
parent
88ab6db976
commit
1dcf46cc5f
|
@ -25,6 +25,7 @@ Housekeeping
|
|||
| `Issue #4460 <https://redmine.postgresql.org/issues/4460>`_ - Add Reverse Engineered SQL tests for FTS Dictionaries.
|
||||
| `Issue #4463 <https://redmine.postgresql.org/issues/4463>`_ - Add Reverse Engineered SQL tests for Domains.
|
||||
| `Issue #4464 <https://redmine.postgresql.org/issues/4464>`_ - Add Reverse Engineered SQL tests for Collations.
|
||||
| `Issue #4468 <https://redmine.postgresql.org/issues/4468>`_ - Add Reverse Engineered SQL tests for Types.
|
||||
|
||||
Bug fixes
|
||||
*********
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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 <OWNER>;
|
||||
|
||||
COMMENT ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'this is test';
|
||||
|
||||
GRANT USAGE ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" TO <OWNER>;
|
||||
|
||||
GRANT USAGE ON TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
|
|
@ -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 <OWNER>;
|
|
@ -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 <OWNER>;
|
|
@ -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 <OWNER>;
|
||||
|
||||
COMMENT ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'this is test';
|
||||
|
||||
GRANT USAGE ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" TO <OWNER>;
|
||||
|
||||
GRANT USAGE ON TYPE public."enum_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
|
|
@ -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 <OWNER>;
|
|
@ -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 <OWNER>;
|
||||
|
||||
COMMENT ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'this is test';
|
||||
|
||||
GRANT USAGE ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#" TO <OWNER>;
|
||||
|
||||
GRANT USAGE ON TYPE public."range_type_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
|
|
@ -0,0 +1,11 @@
|
|||
-- Type: shell_type_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP TYPE public."shell_type_$%{}[]()&*^!@""'`\/#";
|
||||
|
||||
CREATE TYPE public."shell_type_$%{}[]()&*^!@""'`\/#";
|
||||
|
||||
ALTER TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
||||
|
||||
COMMENT ON TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'this is test';
|
|
@ -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 <OWNER>;
|
|
@ -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 <OWNER>;
|
|
@ -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 <OWNER>;
|
|
@ -0,0 +1,8 @@
|
|||
-- Type: shell_type_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP TYPE public."shell_type_$%{}[]()&*^!@""'`\/#";
|
||||
|
||||
CREATE TYPE public."shell_type_$%{}[]()&*^!@""'`\/#";
|
||||
|
||||
ALTER TYPE public."shell_type_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
|
@ -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": {}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue