Skip to content

Commit 82a7a45

Browse files
mkleczekMichal Kleczekadamguo0
authored
Added schema parameter to install_extension (#285)
Co-authored-by: Michal Kleczek <michal.kleczek@sap.com> Co-authored-by: Adam Guo <adamguo@amazon.com>
1 parent 22dbe53 commit 82a7a45

10 files changed

+915
-8
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
EXTENSION = pg_tle
2-
EXTVERSION = 1.4.1
2+
EXTVERSION = 1.5.0
33

44
SCHEMA = pgtle
55
MODULE_big = $(EXTENSION)
66

77
OBJS = src/tleextension.o src/guc-file.o src/feature.o src/passcheck.o src/uni_api.o src/datatype.o src/clientauth.o
88

99
EXTRA_CLEAN = src/guc-file.c pg_tle.control pg_tle--$(EXTVERSION).sql
10-
DATA = pg_tle.control pg_tle--1.0.0.sql pg_tle--1.0.0--1.0.1.sql pg_tle--1.0.1--1.0.4.sql pg_tle--1.0.4.sql pg_tle--1.0.4--1.1.1.sql pg_tle--1.1.0--1.1.1.sql pg_tle--1.1.1.sql pg_tle--1.1.1--1.2.0.sql pg_tle--1.2.0--1.3.0.sql pg_tle--1.3.0--1.3.3.sql pg_tle--1.3.3--1.3.4.sql pg_tle--1.3.4--1.4.0.sql pg_tle--1.4.0--1.4.1.sql
10+
DATA = pg_tle.control pg_tle--1.0.0.sql pg_tle--1.0.0--1.0.1.sql pg_tle--1.0.1--1.0.4.sql pg_tle--1.0.4.sql pg_tle--1.0.4--1.1.1.sql pg_tle--1.1.0--1.1.1.sql pg_tle--1.1.1.sql pg_tle--1.1.1--1.2.0.sql pg_tle--1.2.0--1.3.0.sql pg_tle--1.3.0--1.3.3.sql pg_tle--1.3.3--1.3.4.sql pg_tle--1.3.4--1.4.0.sql pg_tle--1.4.0--1.4.1.sql pg_tle--1.4.1--1.5.0.sql
1111

1212
TESTS = $(wildcard test/sql/*.sql)
1313
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))

pg_tle--1.4.1--1.5.0.sql

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
18+
\echo Use "CREATE EXTENSION pg_tle" to load this file. \quit
19+
20+
DROP FUNCTION pgtle.install_extension
21+
(
22+
name text,
23+
version text,
24+
description text,
25+
ext text,
26+
requires text[]
27+
);
28+
29+
CREATE FUNCTION pgtle.install_extension
30+
(
31+
name text,
32+
version text,
33+
description text,
34+
ext text,
35+
requires text[] DEFAULT NULL,
36+
schema text DEFAULT NULL
37+
)
38+
RETURNS boolean
39+
SET search_path TO 'pgtle'
40+
AS 'MODULE_PATHNAME', 'pg_tle_install_extension'
41+
LANGUAGE C;
42+
43+
REVOKE EXECUTE ON FUNCTION pgtle.install_extension
44+
(
45+
name text,
46+
version text,
47+
description text,
48+
ext text,
49+
requires text[],
50+
schema text
51+
) FROM PUBLIC;
52+
53+
GRANT EXECUTE ON FUNCTION pgtle.install_extension
54+
(
55+
name text,
56+
version text,
57+
description text,
58+
ext text,
59+
requires text[],
60+
schema text
61+
) TO pgtle_admin;

src/tleextension.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ parse_extension_control_file(ExtensionControlFile *control,
914914
control->directory = NULL;
915915
control->module_pathname = NULL;
916916
control->relocatable = false;
917-
control->schema = NULL;
918917
control->superuser = false;
919918
control->trusted = false;
920919
control->encoding = -1; /* encoding is that of the server_side
@@ -999,6 +998,12 @@ build_extension_control_file_string(ExtensionControlFile *control)
999998
quote_literal_cstr(reqstr->data));
1000999
}
10011000

1001+
if (control->schema != NULL)
1002+
{
1003+
appendStringInfo(ctlstr, "schema = %s\n",
1004+
quote_literal_cstr(control->schema));
1005+
}
1006+
10021007
return ctlstr;
10031008
}
10041009

@@ -4398,6 +4403,7 @@ pg_tle_install_extension(PG_FUNCTION_ARGS)
43984403
char *extdesc;
43994404
char *sql_str;
44004405
ArrayType *extrequires;
4406+
char *extschema;
44014407
char *ctlname;
44024408
StringInfo ctlstr;
44034409
char *sqlname;
@@ -4415,7 +4421,7 @@ pg_tle_install_extension(PG_FUNCTION_ARGS)
44154421
Oid ctlfuncid;
44164422
Oid sqlfuncid;
44174423

4418-
if (PG_ARGISNULL(0))
4424+
if (PG_ARGISNULL(0) || !PG_GETARG_DATUM(0))
44194425
ereport(ERROR,
44204426
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
44214427
errmsg("\"name\" is a required argument")));
@@ -4434,29 +4440,29 @@ pg_tle_install_extension(PG_FUNCTION_ARGS)
44344440
errmsg("control file already exists for the %s extension",
44354441
extname)));
44364442

4437-
if (PG_ARGISNULL(1))
4443+
if (PG_ARGISNULL(1) || !PG_GETARG_DATUM(1))
44384444
ereport(ERROR,
44394445
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
44404446
errmsg("\"version\" is a required argument")));
44414447

44424448
extvers = text_to_cstring(PG_GETARG_TEXT_PP(1));
44434449
check_valid_version_name(extvers);
44444450

4445-
if (PG_ARGISNULL(2))
4451+
if (PG_ARGISNULL(2) || !PG_GETARG_DATUM(2))
44464452
ereport(ERROR,
44474453
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
44484454
errmsg("\"description\" is a required argument")));
44494455

44504456
extdesc = text_to_cstring(PG_GETARG_TEXT_PP(2));
44514457

4452-
if (PG_ARGISNULL(3))
4458+
if (PG_ARGISNULL(3) || !PG_GETARG_DATUM(3))
44534459
ereport(ERROR,
44544460
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
44554461
errmsg("\"ext\" is a required argument")));
44564462

44574463
sql_str = text_to_cstring(PG_GETARG_TEXT_PP(3));
44584464

4459-
if (PG_ARGISNULL(4))
4465+
if (PG_ARGISNULL(4) || !PG_GETARG_DATUM(4))
44604466
reqlist = NIL;
44614467
else
44624468
{
@@ -4465,6 +4471,13 @@ pg_tle_install_extension(PG_FUNCTION_ARGS)
44654471
check_requires_list(reqlist);
44664472
}
44674473

4474+
if (PG_ARGISNULL(5) || !PG_GETARG_DATUM(5))
4475+
extschema = NULL;
4476+
else
4477+
{
4478+
extschema = pstrdup(text_to_cstring(PG_GETARG_TEXT_PP(5)));
4479+
}
4480+
44684481
/*
44694482
* Build appropriate function names based on extension name and version.
44704483
*/
@@ -4504,6 +4517,7 @@ pg_tle_install_extension(PG_FUNCTION_ARGS)
45044517
control->default_version = pstrdup(extvers);
45054518
control->comment = pstrdup(extdesc);
45064519
control->requires = reqlist;
4520+
control->schema = extschema;
45074521

45084522
ctlstr = build_extension_control_file_string(control);
45094523

test/expected/pg_tle_api_clusterwide.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,12 @@ SELECT pgtle.uninstall_extension('test_unregister_feature');
370370
DROP SCHEMA pass CASCADE;
371371
NOTICE: drop cascades to function pass.password_check_length_greater_than_8(text,text,pgtle.password_types,timestamp with time zone,boolean)
372372
DROP EXTENSION pg_tle;
373+
ALTER SYSTEM SET pgtle.passcheck_db_name = '';
374+
SELECT pg_reload_conf();
375+
pg_reload_conf
376+
----------------
377+
t
378+
(1 row)
379+
380+
-- reconnect to ensure reload settings are propagated immediately
381+
\c -

0 commit comments

Comments
 (0)