Skip to content

Commit

Permalink
changing upgrade sql script
Browse files Browse the repository at this point in the history
Signed-off-by: pranav jain <[email protected]>
  • Loading branch information
pranavJ23 committed Jan 24, 2025
1 parent 1b83874 commit b8ff28b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '4.6.0'" to load this file. \quit

-- add 'sys' to search path for the convenience
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false);

-- Drops an object if it does not have any dependent objects.
-- Is a temporary procedure for use by the upgrade script. Will be dropped at the end of the upgrade.
-- Please have this be one of the first statements executed in this upgrade script.
CREATE OR REPLACE PROCEDURE babelfish_drop_deprecated_object(object_type varchar, schema_name varchar, object_name varchar) AS
$$
DECLARE
error_msg text;
query1 text;
query2 text;
BEGIN

query1 := pg_catalog.format('alter extension babelfishpg_tsql drop %s %s.%s', object_type, schema_name, object_name);
query2 := pg_catalog.format('drop %s %s.%s', object_type, schema_name, object_name);

execute query1;
execute query2;
EXCEPTION
when object_not_in_prerequisite_state then --if 'alter extension' statement fails
GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT;
raise warning '%', error_msg;
when dependent_objects_still_exist then --if 'drop view' statement fails
GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT;
raise warning '%', error_msg;
end
$$
LANGUAGE plpgsql;

-- Please add your SQLs here
/*
* Note: These SQL statements may get executed multiple times specially when some features get backpatched.
* So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting
* final behaviour.
*/

DO $$
DECLARE
exception_message text;
BEGIN
ALTER FUNCTION sys.suser_name() RENAME TO suser_name_deprecated_4_6_0;

EXCEPTION WHEN OTHERS THEN
GET STACKED DIAGNOSTICS
exception_message = MESSAGE_TEXT;
RAISE WARNING '%', exception_message;
END;
$$;

CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'suser_name_deprecated_4_6_0');

CREATE OR REPLACE FUNCTION sys.suser_name()
RETURNS sys.NVARCHAR(128)
AS 'babelfishpg_tsql', 'suser_name_current_session'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

-- Drops the temporary procedure used by the upgrade script.
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);

-- After upgrade, always run analyze for all babelfish catalogs.
CALL sys.analyze_babelfish_catalogs();

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
12 changes: 6 additions & 6 deletions test/JDBC/expected/sys-suser_sname-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,46 @@ SELECT * FROM sys_suser_sname_view_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


EXEC sys_suser_sname_proc_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


SELECT sys_suser_sname_func_vu_prepare()
GO
~~START~~
varchar
jdbc_user
<NULL>
~~END~~


SELECT * FROM sys_suser_name_view_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


EXEC sys_suser_name_proc_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


SELECT sys_suser_name_func_vu_prepare()
GO
~~START~~
varchar
jdbc_user
<NULL>
~~END~~

0 comments on commit b8ff28b

Please sign in to comment.