/* * * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ /* * 1. Test that an existing version of an extension cannot be installed again * 2. Test that a different version of an installed extension can be installed * 3. Test that CREATE EXTENSION with an explicit version automatically updates * to that version * 4. Test that CREATE EXTENSION automatically updates to default version */ \pset pager off CREATE EXTENSION pg_tle; -- install version 1.0 of an extension SELECT pgtle.install_extension ( 'test123', '1.0', 'Test TLE Functions', $_pgtle_$ CREATE OR REPLACE FUNCTION test123_func() RETURNS INT AS $$ ( SELECT 42 )$$ LANGUAGE sql; $_pgtle_$ ); install_extension ------------------- t (1 row) CREATE EXTENSION test123; SELECT test123_func(); test123_func -------------- 42 (1 row) DROP EXTENSION test123; -- an existing version of an extension cannot be installed again SELECT pgtle.install_extension ( 'test123', '1.0', 'Test TLE Functions', $_pgtle_$ CREATE OR REPLACE FUNCTION test123_func() RETURNS INT AS $$ ( SELECT 21 )$$ LANGUAGE sql; $_pgtle_$ ); ERROR: extension "test123" already installed -- but a different version of the same extension can be installed SELECT pgtle.install_extension ( 'test123', '1.1', 'Test TLE Functions', $_pgtle_$ CREATE OR REPLACE FUNCTION test123_func() RETURNS INT AS $$ ( SELECT 21 )$$ LANGUAGE sql; CREATE OR REPLACE FUNCTION test123_func_2() RETURNS INT AS $$ ( SELECT 212121 )$$ LANGUAGE sql; $_pgtle_$ ); install_extension ------------------- t (1 row) CREATE EXTENSION test123; SELECT test123_func(); test123_func -------------- 21 (1 row) SELECT test123_func_2(); test123_func_2 ---------------- 212121 (1 row) DROP EXTENSION test123; -- uninstall version 1.1 SELECT pgtle.set_default_version('test123', '1.0'); set_default_version --------------------- t (1 row) SELECT pgtle.uninstall_extension('test123', '1.1'); uninstall_extension --------------------- t (1 row) CREATE EXTENSION test123; SELECT test123_func(); test123_func -------------- 42 (1 row) SELECT test123_func_2(); -- expect to fail ERROR: function test123_func_2() does not exist LINE 1: SELECT test123_func_2(); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. DROP EXTENSION test123; -- create update path to 1.1 instead SELECT pgtle.install_update_path ( 'test123', '1.0', '1.1', $_pgtle_$ CREATE OR REPLACE FUNCTION test123_func() RETURNS INT AS $$ ( SELECT 21 )$$ LANGUAGE sql; CREATE OR REPLACE FUNCTION test123_func_2() RETURNS INT AS $$ ( SELECT 212121 )$$ LANGUAGE sql; $_pgtle_$ ); install_update_path --------------------- t (1 row) -- test that CREATE EXTENSION version 1.1 works CREATE EXTENSION test123 version '1.1'; SELECT test123_func(); test123_func -------------- 21 (1 row) SELECT test123_func_2(); test123_func_2 ---------------- 212121 (1 row) DROP EXTENSION test123; -- if version 1.1 is set as default, then it should be create-able via the upgrade path SELECT pgtle.set_default_version('test123', '1.1'); set_default_version --------------------- t (1 row) CREATE EXTENSION test123; SELECT test123_func(); test123_func -------------- 21 (1 row) SELECT test123_func_2(); test123_func_2 ---------------- 212121 (1 row) DROP EXTENSION test123; -- sanity check that uninstall works SELECT pgtle.uninstall_extension('test123'); uninstall_extension --------------------- t (1 row) -- clean up DROP EXTENSION pg_tle CASCADE; DROP SCHEMA pgtle; DROP ROLE pgtle_admin;