Repository navigation
refactor: create extension from beginning of lineage - #304
AndrewJackson2020 wants to merge 2 commits into
Conversation
|
objects match between branches, diffed in vim and they look the same this PR master |
|
Also diffed the pg_dump (after dropping all objects form the extension) no diffs. Weird that tests are failing though. |
|
I ran the previous upgrade test incorrectly. There definitely are diffs. Seems like an upgrade was missed at some point. |
|
Agree with the direction 👍 |
37fbfdc to
1c7b517
Compare
|
Went ahead and patched one missed diff. I think it matches now. |
1c7b517 to
67ef171
Compare
|
Okay I messed up the previous diff, there is still one differential between the upgrade scripts and the snapshot sql script. One of these diffs I believe was added because the table stated out with a primary key which was dropped without removing the null constraint. I suspect the snapshot sql file is incorrect and we do in fact want this column to be non nullable. This does create issues though as now we have some of the fleet without this constant and others with it. I believe that this was introduced in 07e6314 as apart of the v0.5 release. |
|
last diff is shown below. seems like it was introduced in 8c059af. pg_net.sql was updated but not the corresponding upgrade script for the v0.7.1 release.vk/ master and in this commit |
a6421a0 to
5eaf0f6
Compare
hanefi
left a comment
There was a problem hiding this comment.
Looks good overall. However I do not feel confident to approve it and would like another set of eyes to take a look.
|
Nitpick: looks like this should be a |
6aebc3d to
00ff5c2
Compare
Changed. Though I will say that this refactor exposed some inconsistencies. |
0250e90 to
95412db
Compare
|
I think this PR should be good now. I added a new file in the root called pg_net.sql that essentially is a point in time snapshot of the state of the extension built via pg_dump. Its state is enforced via a CI job. Used the script in this PR to take a schema dump of the current state of the extension here and in master branch. @utkarash2991 please take a look at this when you have a minute, would like to merge this week if possible (and then move onto other pg_net stuff that require schema changes like the row level security stuff) |
95412db to
055d3f6
Compare
|
any objections to merging this by tomorrow? IMO this PR is basically blocking any other PR that requires schema change and would like to get this merged. |
| volatile | ||
| language plpgsql | ||
| as $$ | ||
| begin; |
There was a problem hiding this comment.
@AndrewJackson2020 I think there is a problem here:
psql (17.6)
Type "help" for help.
postgres=# create or replace function t_collect() returns void language plpgsql as $$
begin;
raise notice 'The net.http_collect_response function is deprecated.';
end;
$$;postgres$# postgres$# postgres$# postgres$#
ERROR: syntax error at or near ";"
LINE 2: begin;
^
postgres=# set check_function_bodies = off;
SET
postgres=# create or replace function t_collect() returns void language plpgsql as $$
begin;
raise notice 'The net.http_collect_response function is deprecated.';
end;
$$;postgres$# postgres$# postgres$# postgres$#
CREATE FUNCTION
postgres=# select t_collect();
ERROR: syntax error at or near ";"
LINE 2: begin;
^
QUERY:
begin;
raise notice 'The net.http_collect_response function is deprecated.';
end;
CONTEXT: compilation of PL/pgSQL function "t_collect" near line 1
IIUC the scripts are passing due to this code logic in extension.c : https://github.com/postgres/postgres/blob/master/src/backend/commands/extension.c#L1337
So the function wrong syntax is not parsed during creation. Thats why it wasn't caught .
There was a problem hiding this comment.
May be for sanity checks lets add the test calling those functions ?
There was a problem hiding this comment.
If this function is never called in test then agree that should be added here, agreed.
Another idea: I have a PR that integrates plpgsql_check into the build system and test suite. Maybe we should consider merging that first? I just tested on that branch and it would definitely have caught this issue.
aj@Andrews-MacBook-Pro:~/Repos/mono/external/repos/supabase/pg_net/master/ > git diff
diff --git a/sql/pg_net.sql b/sql/pg_net.sql
index 385ee2f..740b267 100644
--- a/sql/pg_net.sql
+++ b/sql/pg_net.sql
@@ -345,7 +345,7 @@ create or replace function net.http_collect_response(
returns net.http_response_result
language plpgsql
as $$
-begin
+begin;
raise notice 'The net.http_collect_response function is deprecated.';
return net._http_collect_response(request_id, async);
end;15:07:17 postgres@[local:/tmp/nix-shell.GBVekV/tmp.hRvcDL8lq9]:5432/postgres 80995 =#
SELECT p.oid, p.proname, plpgsql_check_function(p.oid)
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_proc p ON pronamespace = n.oid
JOIN pg_catalog.pg_language l ON p.prolang = l.oid
WHERE l.lanname = 'plpgsql' AND p.prorettype <> 2279;
oid | proname | plpgsql_check_function
-------+-----------------------+--------------------------------------------------------------------------------
16430 | http_collect_response | error:42601:syntax error at or near ";"
16430 | http_collect_response | Query:
16430 | http_collect_response | begin;
16430 | http_collect_response | -- ^
16430 | http_collect_response | raise notice 'The net.http_collect_response function is deprecated.';
16430 | http_collect_response | return net._http_collect_response(request_id, async);
16430 | http_collect_response | end;
16430 | http_collect_response |
16430 | http_collect_response | Context: compilation of PL/pgSQL function "http_collect_response" near line 1
(9 rows)
There was a problem hiding this comment.
I added the semicolon. Turns out that function never worked from day 1 because it needed to call the last statement with RETURN and not SELECT. Maybe we should just get rid of the thing entirely since it was marked for deprecation anyway?
There was a problem hiding this comment.
Thinking about this more we should definitely not be removing this function in thisPR. @utkarash2991 does this PR look good after the above changes? If so would like to merge this week.
| END; | ||
| $$; | ||
| EOF) \ | ||
| --command="\! pg_dump --schema=net --user=postgres --schema-only | grep -v -- -- | grep -v '^SET .*;' | grep -v 'SELECT pg_catalog.set_config' | pgpp > pg_net.sql" |
There was a problem hiding this comment.
I think the grep -v -- -- can create problem in some cases. I got that its been added to remove the pg_dump comment headers. But I believe it can lead to loss of contents in function body .
Please see below, for ex:
The comments in the function got removed in pg_net.sql generated file:
-- request_id reference
request_id bigint,
-- when `true`, return immediately. when `false` wait for the request to complete before returning
async bool default true
)
-- http response composite wrapped in a result type
returns net.http_response_result
language plpgsql
as $$
declare
rec net._http_response;
req_exists boolean;
begin
if not async then
perform net._await_response(request_id);
end if;
select *
into rec
from net._http_response
where id = request_id;
if rec is null or rec.error_msg is not null then
-- The request is either still processing or the request_id provided does not exist
-- TODO: request in progress is indistinguishable from request that doesn't exist
-- No request matching request_id found
return (
'ERROR',
coalesce(rec.error_msg, 'request matching request_id not found'),
null
)::net.http_response_result;
end if;
....
Ideally the function body looses comments which can be harmless but what if the function body written like:
-- input
CREATE FUNCTION f() AS $body$
-- an indented comment inside the body
select 1 where x like '%--%';
$body$;
-- after grep -v -- --
CREATE FUNCTION f() AS $body$
$body$;
I think we need to fix this
There was a problem hiding this comment.
Yeah good catch. will fix.
There was a problem hiding this comment.
This is fixed. I ended up just removing that statement altogether. pglast (the postgres SQL formatter that is the last stage of the pipe) by default removes comments anyway.
[nix-shell:~/Repos/mono/external/repos/supabase/pg_net/master]$ pgpp --help | grep commen
-C, --preserve-comments
preserve comments in the statement
ac61c5c to
5db137b
Compare
|
@AndrewJackson2020 LGTM. |
Thank you. Will double check and merge today. |
|
final checkout looks good |
7671b82 to
788d5bc
Compare
6be8cb4 to
c5836a5
Compare
|
One last comparison between the current master and this branch before merging. As expected the only diff is the non functioning SQL statement. |
Currently in pg_net the upgrade code path is different from the create extension code path. When running tests internally we are not able to do true upgrade testing because the initial release of pg_net, 0.1 is not avaiable. This commit cherry picks 0.1 from the 0.1 tag, removes the pg_net.sql file and forces all create extension to happen by creating 0.1 and upgrading all the way until the current version. This commit also corrects a missing migration that was added pg_net.sql but not in the uprade script during 8b55e96. Regarding this missing migraiton, this may need an additional PR to correct somehow. It is not hard to imagine instances in the wild that do not have this modified function that should. I think this is a better approach and will open us up for upgrade testing internal to the repo. This commit
c5836a5 to
325c7de
Compare
Currently in pg_net the upgrade code path is different from the create extension code path. When running tests internally we are not able to do true upgrade testing because the initial release of pg_net, 0.1 is not avaiable. This commit cherry picks 0.1 from the 0.1 tag, removes the pg_net.sql file and forces all create extension to happen by creating 0.1 and upgrading all the way until the current version. I think this is a better approach and will open us up for upgrade testing internal to the repo.