postgre function analyser

This commit is contained in:
Jan Prochazka
2021-06-10 14:11:26 +02:00
parent f5ea87da7b
commit 3fa71cc94a
3 changed files with 9 additions and 0 deletions

View File

@@ -54,6 +54,13 @@ const engines = [
drop1: 'DROP PROCEDURE obj1',
drop2: 'DROP PROCEDURE obj2',
},
{
type: 'functions',
create1: 'CREATE FUNCTION obj1() returns int LANGUAGE plpgsql AS $$ declare res integer; begin select count(*) into res from t1; return res; end; $$',
create2: 'CREATE FUNCTION obj2() returns int LANGUAGE plpgsql AS $$ declare res integer; begin select count(*) into res from t2; return res; end; $$',
drop1: 'DROP FUNCTION obj1',
drop2: 'DROP FUNCTION obj2',
},
],
},
{

View File

@@ -139,6 +139,7 @@ class Analyser extends DatabaseAnalyser {
.filter(x => x.object_type == 'FUNCTION')
.map(func => ({
objectId: `functions:${func.schema_name}.${func.pure_name}`,
createSql: `CREATE FUNCTION "${func.schema_name}"."${func.pure_name}"() RETURNS ${func.data_type} LANGUAGE ${func.language}\nAS\n$$\n${func.definition}\n$$`,
pureName: func.pure_name,
schemaName: func.schema_name,
contentHash: func.hash_code,

View File

@@ -5,6 +5,7 @@ select
routine_definition as "definition",
md5(routine_definition) as "hash_code",
routine_type as "object_type",
data_type as "data_type",
external_language as "language"
from
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'