Skip to content

refactor: create extension from beginning of lineage - #304

Open
AndrewJackson2020 wants to merge 2 commits into
masterfrom
enable_upgrade_test
Open

AndrewJackson2020 wants to merge 2 commits into
masterfrom
enable_upgrade_test

Conversation

@AndrewJackson2020

Copy link
Copy Markdown
Contributor

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.

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

objects match between branches, diffed in vim and they look the same

this PR

\dx+ pg_net
              Objects in extension "pg_net"
                    Object description
----------------------------------------------------------
 function net._await_response(bigint)
 function net._encode_url_with_params_array(text,text[])
 function net._http_collect_response(bigint,boolean)
 function net._urlencode_string(character varying)
 function net.check_worker_is_up()
 function net.http_collect_response(bigint,boolean)
 function net.http_delete(text,jsonb,jsonb,integer,jsonb)
 function net.http_get(text,jsonb,jsonb,integer)
 function net.http_post(text,jsonb,jsonb,jsonb,integer)
 function net.wait_until_running()
 function net.wake()
 function net.worker_restart()
 schema net
 sequence net.http_request_queue_id_seq
 table net._http_response
 table net.http_request_queue
 type net._http_response
 type net._http_response[]
 type net.http_method
 type net.http_method[]
 type net.http_request_queue
 type net.http_request_queue[]
 type net.http_response
 type net.http_response[]
 type net.http_response_result
 type net.http_response_result[]
 type net.request_status
 type net.request_status[]
(28 rows)

master

\dx+ pg_net
              Objects in extension "pg_net"
                    Object description
----------------------------------------------------------
 function net._await_response(bigint)
 function net._encode_url_with_params_array(text,text[])
 function net._http_collect_response(bigint,boolean)
 function net._urlencode_string(character varying)
 function net.check_worker_is_up()
 function net.http_collect_response(bigint,boolean)
 function net.http_delete(text,jsonb,jsonb,integer,jsonb)
 function net.http_get(text,jsonb,jsonb,integer)
 function net.http_post(text,jsonb,jsonb,jsonb,integer)
 function net.wait_until_running()
 function net.wake()
 function net.worker_restart()
 schema net
 sequence net.http_request_queue_id_seq
 table net._http_response
 table net.http_request_queue
 type net._http_response
 type net._http_response[]
 type net.http_method
 type net.http_method[]
 type net.http_request_queue
 type net.http_request_queue[]
 type net.http_response
 type net.http_response[]
 type net.http_response_result
 type net.http_response_result[]
 type net.request_status
 type net.request_status[]
(28 rows)

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

Also diffed the pg_dump (after dropping all objects form the extension) no diffs. Weird that tests are failing though.
enable_upgrade_test.sql
master.sql

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

I ran the previous upgrade test incorrectly. There definitely are diffs. Seems like an upgrade was missed at some point.
enable_upgrade_test.sql
master.sql

aj@Andrews-MacBook-Pro:~/ > diff ~/master.sql ~/enable_upgrade_test.sql
5c5
< \restrict On04JqoZrcHcQdVn5XasXuffHUmPMEV2jHTlrkoVbFVRhLNkwTCfj2FsADuRYRh
---
> \restrict 483rurknHmZOowoW9NAMkybEoSfrJp1vxbLJUaSxx7vIhh3Ydaw0TjIErl7Qc4h
141c141
<     if rec is null or rec.error_msg is not null then
---
>     if rec is null then
149c149
<             coalesce(rec.error_msg, 'request matching request_id not found'),
---
>             'request matching request_id not found',
216d215
< begin
219d217
< end;
407c405
<     id bigint,
---
>     id bigint NOT NULL,
526c524
< \unrestrict On04JqoZrcHcQdVn5XasXuffHUmPMEV2jHTlrkoVbFVRhLNkwTCfj2FsADuRYRh
---
> \unrestrict 483rurknHmZOowoW9NAMkybEoSfrJp1vxbLJUaSxx7vIhh3Ydaw0TjIErl7Qc4h

@steve-chavez

Copy link
Copy Markdown
Member

Agree with the direction 👍

@AndrewJackson2020 AndrewJackson2020 changed the title fix: create extension from beginning of lineaage fix: create extension from beginning of lineage Oct 2, 2026
@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

Went ahead and patched one missed diff. I think it matches now.

enable_upgrade_test.sql
master.sql

@AndrewJackson2020
AndrewJackson2020 marked this pull request as ready for review October 2, 2026 03:08
@AndrewJackson2020
AndrewJackson2020 requested a review from a team as a code owner October 2, 2026 03:08
@AndrewJackson2020

AndrewJackson2020 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Okay I messed up the previous diff, there is still one differential between the upgrade scripts and the snapshot sql script.
enable_upgrade_test.sql
master.sql

aj@Andrews-MacBook-Pro:~/Repos/mono/external/repos/supabase/pg_net/master/ > diff ~/master.sql ~/enable_upgrade_test.sql
5c5
< \restrict ugUWfLnLHqxa6A2ItGZAaNfLRp6hQZKE9MOkRbtpdaBG8pJeCrcluItBLdaVEyg
---
> \restrict 6cShUWyS2JNmDN9odrIaWGDVQQ4gLQzaayogS6jtUDKqxeYcN85WucSbw1pNJSA
216d215
< begin
219d217
< end;
407c405
<     id bigint,
---
>     id bigint NOT NULL,
526c524
< \unrestrict ugUWfLnLHqxa6A2ItGZAaNfLRp6hQZKE9MOkRbtpdaBG8pJeCrcluItBLdaVEyg
---
> \unrestrict 6cShUWyS2JNmDN9odrIaWGDVQQ4gLQzaayogS6jtUDKqxeYcN85WucSbw1pNJSA

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.

22:54:53 postgres@[local:/tmp/nix-shell.Kn9i1d/tmp.aIxEqjvdqX]:5432/postgres  68838 =#
create table _http_response(
    id bigint primary key,
    status_code integer,
    content_type text,
    headers jsonb,
    content text,
    timed_out bool,
    error_msg text
);
2026-10-01 22:54:59.019 CDT [68838] DEBUG:  building index "pg_toast_16457_index" on table "pg_toast_16457" serially
2026-10-01 22:54:59.019 CDT [68838] DEBUG:  index "pg_toast_16457_index" can safely use deduplication
2026-10-01 22:54:59.019 CDT [68838] DEBUG:  CREATE TABLE / PRIMARY KEY will create implicit index "_http_response_pkey" for table "_http_response"
2026-10-01 22:54:59.019 CDT [68838] DEBUG:  building index "_http_response_pkey" on table "_http_response" serially
2026-10-01 22:54:59.019 CDT [68838] DEBUG:  index "_http_response_pkey" can safely use deduplication
CREATE TABLE
22:54:59 postgres@[local:/tmp/nix-shell.Kn9i1d/tmp.aIxEqjvdqX]:5432/postgres  68838 =#
\d _http_response
              Table "public._http_response"
    Column    |  Type   | Collation | Nullable | Default
--------------+---------+-----------+----------+---------
 id           | bigint  |           | not null |
 status_code  | integer |           |          |
 content_type | text    |           |          |
 headers      | jsonb   |           |          |
 content      | text    |           |          |
 timed_out    | boolean |           |          |
 error_msg    | text    |           |          |
Indexes:
    "_http_response_pkey" PRIMARY KEY, btree (id)

22:55:03 postgres@[local:/tmp/nix-shell.Kn9i1d/tmp.aIxEqjvdqX]:5432/postgres  68838 =#
alter table _http_response drop constraint if exists _http_response_pkey cascade;
ALTER TABLE
22:55:11 postgres@[local:/tmp/nix-shell.Kn9i1d/tmp.aIxEqjvdqX]:5432/postgres  68838 =#
\d _http_response
              Table "public._http_response"
    Column    |  Type   | Collation | Nullable | Default
--------------+---------+-----------+----------+---------
 id           | bigint  |           | not null |
 status_code  | integer |           |          |
 content_type | text    |           |          |
 headers      | jsonb   |           |          |
 content      | text    |           |          |
 timed_out    | boolean |           |          |
 error_msg    | text    |           |          |

@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

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

CREATE FUNCTION net.http_collect_response(request_id bigint, async boolean DEFAULT true) RETURNS net.http_response_result
    LANGUAGE plpgsql
    AS $$
begin
  raise notice 'The net.http_collect_response function is deprecated.';
  select net._http_collect_response(request_id, async);
end;
$$;

and in this commit

CREATE FUNCTION net.http_collect_response(request_id bigint, async boolean DEFAULT true) RETURNS net.http_response_result
    LANGUAGE plpgsql
    AS $$
  raise notice 'The net.http_collect_response function is deprecated.';
  select net._http_collect_response(request_id, async);
$$;

@hanefi hanefi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. However I do not feel confident to approve it and would like another set of eyes to take a look.

Comment thread .gitignore
Comment thread Makefile Outdated
@steve-chavez

Copy link
Copy Markdown
Member

Nitpick: looks like this should be a refactor and not a fix.

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
@AndrewJackson2020 AndrewJackson2020 changed the title fix: create extension from beginning of lineage refactor: create extension from beginning of lineage Oct 14, 2026
@AndrewJackson2020

Copy link
Copy Markdown
Contributor Author

Nitpick: looks like this should be a refactor and not a fix.

Changed. Though I will say that this refactor exposed some inconsistencies.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants