Add proper indentation to the code while generating functions, procedures, and trigger functions. Fixes #3851

This commit is contained in:
Rahul Shirsat 2020-06-29 12:36:28 +05:30 committed by Akshay Joshi
parent 2db518c9c6
commit 7add777b21
53 changed files with 208 additions and 93 deletions

View File

@ -14,7 +14,9 @@ Housekeeping
************
| `Issue #5326 <https://redmine.postgresql.org/issues/5326>`_ - Improve code coverage and API test cases for Domain and Domain Constraints.
| `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows.
Bug fixes
*********
| `Issue #3851 <https://redmine.postgresql.org/issues/3851>`_ - Add proper indentation to the code while generating functions, procedures, and trigger functions.
| `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows.

View File

@ -1009,6 +1009,8 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
resp_data['func_args_without'] = ', '.join(args_without_name)
self.reformat_prosrc_code(resp_data)
if self.node_type == 'procedure':
object_type = 'procedure'
if 'provolatile' in resp_data:
@ -1292,6 +1294,8 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
for v in data['variables']['added']:
data['merged_variables'].append(v)
self.reformat_prosrc_code(data)
SQL = render_template(
"/".join([self.sql_template_path, 'update.sql']),
data=data, o_data=old_data
@ -1336,6 +1340,9 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
data['func_args'] = args.strip(' ')
data['func_args_without'] = ', '.join(args_without_name)
self.reformat_prosrc_code(data)
# Create mode
SQL = render_template("/".join([self.sql_template_path,
'create.sql']),
@ -1680,6 +1687,30 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
json_resp=False)
return sql
def reformat_prosrc_code(self, data):
"""
:param data:
:return:
"""
if 'prosrc' in data and data['prosrc'] is not None:
is_prc_version_lesser_than_11 = \
self.node_type == 'procedure' and\
self.manager.sversion <= 110000
data['prosrc'] = re.sub(r"^\s+", '',
re.sub(r"\s+$", '',
data['prosrc']))
if not is_prc_version_lesser_than_11:
if data['prosrc'].startswith('\n') is False:
data['prosrc'] = ''.join(
('\n', data['prosrc']))
if data['prosrc'].endswith('\n') is False:
data['prosrc'] = ''.join(
(data['prosrc'], '\n'))
@check_precondition
def fetch_objects_to_compare(self, sid, did, scid, oid=None):
"""

View File

@ -5,9 +5,11 @@
CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
COMMENT ON PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(integer)
IS 'some comment';

View File

@ -6,9 +6,11 @@ CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
SET application_name='pgadmin'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
COMMENT ON PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(integer)
IS 'some comment';

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
STABLE LEAKPROOF STRICT SECURITY DEFINER
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
IMMUTABLE LEAKPROOF STRICT SECURITY DEFINER
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
SET application_name='appname2'
SET search_path=public, pg_catalog
SET array_nulls='true'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW
ROWS 4321
SET application_name='appname'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
ROWS 4321
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -5,6 +5,8 @@
CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
STABLE LEAKPROOF STRICT SECURITY DEFINER
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
IMMUTABLE LEAKPROOF STRICT SECURITY DEFINER
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
SET application_name='appname2'
SET search_path=public, pg_catalog
SET array_nulls='true'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW
ROWS 4321
SET application_name='appname'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
ROWS 4321
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO postgres;

View File

@ -5,9 +5,11 @@
CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
COMMENT ON PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(integer)
IS 'some comment';

View File

@ -6,9 +6,11 @@ CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
SET application_name='pgadmin'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
COMMENT ON PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(integer)
IS 'some comment';

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
STABLE LEAKPROOF STRICT SECURITY DEFINER
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
IMMUTABLE LEAKPROOF STRICT SECURITY DEFINER
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
SET application_name='appname2'
SET search_path=public, pg_catalog
SET array_nulls='true'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW
ROWS 4321
SET application_name='appname'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
ROWS 4321
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -5,6 +5,8 @@
CREATE OR REPLACE PROCEDURE public."Proc1_$%{}[]()&*^!@""'`\/#"(
i1 integer)
LANGUAGE 'plpgsql'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
STABLE LEAKPROOF STRICT SECURITY DEFINER
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
IMMUTABLE LEAKPROOF STRICT SECURITY DEFINER
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
SET application_name='appname2'
SET search_path=public, pg_catalog
SET array_nulls='true'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW
ROWS 4321
SET application_name='appname'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
ROWS 4321
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
STABLE LEAKPROOF STRICT SECURITY DEFINER
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
IMMUTABLE LEAKPROOF STRICT SECURITY DEFINER
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
SET application_name='appname2'
SET search_path=public, pg_catalog
SET array_nulls='true'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -9,9 +9,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW
ROWS 4321
SET application_name='appname'
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -7,9 +7,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;

View File

@ -10,9 +10,11 @@ CREATE FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
ROWS 4321
SET application_name='appname'
SET search_path=public, pg_temp
AS $BODY$begin
AS $BODY$
begin
select 1;
end;$BODY$;
end;
$BODY$;
ALTER FUNCTION public."Trig1_$%{}[]()&*^!@""'`\/#"()
OWNER TO enterprisedb;