Skip to content

Commit 832e2cb

Browse files
authored
Merge branch 'develop' into fix/grant-vault-privs-to-service_role
2 parents a911b07 + 1ffe2e3 commit 832e2cb

File tree

11 files changed

+89
-49
lines changed

11 files changed

+89
-49
lines changed

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ postgres_major:
99

1010
# Full version strings for each major version
1111
postgres_release:
12-
postgresorioledb-17: "17.0.1.068-orioledb"
13-
postgres17: "17.4.1.018"
14-
postgres15: "15.8.1.075"
12+
postgresorioledb-17: "17.0.1.070-orioledb"
13+
postgres17: "17.4.1.020"
14+
postgres15: "15.8.1.077"
1515

1616
# Non Postgres Extensions
1717
pgbouncer_release: "1.19.0"

flake.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@
154154
x:
155155
x != ./nix/ext/timescaledb.nix &&
156156
x != ./nix/ext/timescaledb-2.9.1.nix &&
157-
x != ./nix/ext/plv8.nix &&
158-
x != ./nix/ext/pgjwt.nix
157+
x != ./nix/ext/plv8.nix
159158
) ourExtensions;
160159

161160
orioledbExtensions = orioleFilteredExtensions ++ [ ./nix/ext/orioledb.nix ];
162-
dbExtensions17 = orioleFilteredExtensions;
161+
dbExtensions17 = builtins.filter (
162+
x:
163+
x != ./nix/ext/pgjwt.nix
164+
) orioleFilteredExtensions;
163165
getPostgresqlPackage = version:
164166
pkgs.postgresql."postgresql_${version}";
165167
# Create a 'receipt' file for a given postgresql package. This is a way

migrations/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,22 @@ After making changes to migrations, you should update the schema.sql files for e
134134
nix run .#dbmate-tool -- --version all
135135
```
136136

137-
This will create a schema.sql file for each major version of PostgreSQL. Commit these changes to your repository and push to your branch. The test.yml workflow will verify these changes against the test matrix.
137+
This will create automatically schema.sql file for each major version of PostgreSQL and OrioleDB (the files are named like `schema-<ver>`, `schema-oriole-<ver>`). Commit these changes to your repository and push to your branch. The workflow in `.github/workflows/test.yml` will re-run this command in CI, and perform a git diff to verify the idempotency of the migrations, and that the latest changes have been committed.
138+
138139
## Testing
139140

140-
Migrations are tested in CI to ensure they do not raise an exception against previously released `supabase/postgres` docker images. The full version matrix is at [test.yml](./.github/workflows/test.yml) in the `supabase-version` variable.
141+
In addition to ci test mentioned above, you can test migrations locally by running the following test for each major version of postgres one at a time.
142+
143+
Examples:
144+
145+
```
146+
nix build .#checks.aarch64-darwin.psql_15 -L
147+
nix build .#checks.aarch64-darwin.psql_17 -L
148+
nix build .#checks.aarch64-darwin.psql_orioledb-17 -L
149+
```
150+
151+
(Note that the evaluation and nix build of the postgres packages "bundle" of each major version must succeed here, even though we run one version at a time. If you made changes to postgres or extensions, or wrappers those may rebuild here when you run this. Otherwise they will usually download the prebuilt version from the supabase nix binary cache)
152+
153+
At the end of these commands, you will see the output of both `pg_regress` tests, and migration tests
154+
155+
see [Adding Tests](https://github.com/supabase/postgres/blob/develop/nix/docs/adding-tests.md) for more information.

migrations/db/init-scripts/00000000000000-initial-schema.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ do $$
2222
begin
2323
if exists (select 1 from pg_available_extensions where name = 'pgjwt') then
2424
if not exists (select 1 from pg_extension where extname = 'pgjwt') then
25-
create extension if not exists pgjwt with schema "extensions" cascade;
25+
if current_setting('server_version_num')::int / 10000 = 15 then
26+
create extension if not exists pgjwt with schema "extensions" cascade;
27+
end if;
2628
end if;
2729
end if;
2830
end $$;

migrations/schema-15.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
--
2+
-- PostgreSQL database dump
3+
--
4+
5+
-- Dumped from database version 15.8
6+
-- Dumped by pg_dump version 15.8
7+
18
SET statement_timeout = 0;
29
SET lock_timeout = 0;
310
SET idle_in_transaction_session_timeout = 0;
@@ -1004,8 +1011,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
10041011
-- PostgreSQL database dump complete
10051012
--
10061013

1007-
1008-
--
1009-
-- Dbmate schema migrations
1010-
--
1011-

migrations/schema-17.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
--
2+
-- PostgreSQL database dump
3+
--
4+
5+
-- Dumped from database version 17.4
6+
-- Dumped by pg_dump version 17.4
7+
18
SET statement_timeout = 0;
29
SET lock_timeout = 0;
310
SET idle_in_transaction_session_timeout = 0;
@@ -991,8 +998,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
991998
-- PostgreSQL database dump complete
992999
--
9931000

994-
995-
--
996-
-- Dbmate schema migrations
997-
--
998-

migrations/schema-orioledb-17.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
--
2+
-- PostgreSQL database dump
3+
--
4+
5+
-- Dumped from database version 17.0
6+
-- Dumped by pg_dump version 17.0
7+
18
SET statement_timeout = 0;
29
SET lock_timeout = 0;
310
SET idle_in_transaction_session_timeout = 0;
@@ -1005,8 +1012,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
10051012
-- PostgreSQL database dump complete
10061013
--
10071014

1008-
1009-
--
1010-
-- Dbmate schema migrations
1011-
--
1012-

nix/tests/expected/pgbouncer.out

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,30 @@ SELECT
5858
FROM pg_proc p
5959
JOIN schema_obj s ON s.oid = p.pronamespace
6060
CROSS JOIN LATERAL aclexplode(p.proacl) AS acl
61-
ORDER BY object_name, grantee, privilege_type;
61+
ORDER BY object_name, grantee, privilege_type;
6262
schema | object_name | grantee | privilege_type
6363
-----------+-------------+----------------+----------------
6464
pgbouncer | get_auth | pgbouncer | EXECUTE
6565
pgbouncer | get_auth | postgres | EXECUTE
6666
pgbouncer | get_auth | supabase_admin | EXECUTE
6767
(3 rows)
6868

69+
-- Ensure that pgbouncer.get_auth() function does not return an expired password
70+
create role test_expired_user_password with login password 'expired_password' valid until '2000-01-01 00:00:00+00';
71+
create role test_valid_user_password with login password 'valid_password' valid until '2100-01-01 00:00:00+00';
72+
-- Update the pg_authid catalog directly to replace with a known SCRAM hash
73+
update pg_authid set rolpassword = 'SCRAM-SHA-256$4096:testsaltbase64$storedkeybase64$serverkeybase64' where rolname = 'test_valid_user_password';
74+
select pgbouncer.get_auth('test_expired_user_password');
75+
get_auth
76+
-------------------------------
77+
(test_expired_user_password,)
78+
(1 row)
79+
80+
select pgbouncer.get_auth('test_valid_user_password');
81+
get_auth
82+
----------------------------------------------------------------------------------------------
83+
(test_valid_user_password,SCRAM-SHA-256$4096:testsaltbase64$storedkeybase64$serverkeybase64)
84+
(1 row)
85+
86+
drop role test_expired_user_password;
87+
drop role test_valid_user_password;

nix/tests/prime.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ do $$
6161
begin
6262
if exists (select 1 from pg_available_extensions where name = 'pgjwt') then
6363
if not exists (select 1 from pg_extension where extname = 'pgjwt') then
64-
create extension if not exists pgjwt;
64+
if current_setting('server_version_num')::int / 10000 = 15 then
65+
create extension if not exists pgjwt;
66+
end if;
6567
end if;
6668
end if;
6769
end $$;

nix/tests/sql/pgbouncer.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@ SELECT
5050
FROM pg_proc p
5151
JOIN schema_obj s ON s.oid = p.pronamespace
5252
CROSS JOIN LATERAL aclexplode(p.proacl) AS acl
53-
ORDER BY object_name, grantee, privilege_type;
53+
ORDER BY object_name, grantee, privilege_type;
54+
55+
-- Ensure that pgbouncer.get_auth() function does not return an expired password
56+
create role test_expired_user_password with login password 'expired_password' valid until '2000-01-01 00:00:00+00';
57+
create role test_valid_user_password with login password 'valid_password' valid until '2100-01-01 00:00:00+00';
58+
-- Update the pg_authid catalog directly to replace with a known SCRAM hash
59+
update pg_authid set rolpassword = 'SCRAM-SHA-256$4096:testsaltbase64$storedkeybase64$serverkeybase64' where rolname = 'test_valid_user_password';
60+
61+
select pgbouncer.get_auth('test_expired_user_password');
62+
63+
select pgbouncer.get_auth('test_valid_user_password');
64+
65+
drop role test_expired_user_password;
66+
drop role test_valid_user_password;

0 commit comments

Comments
 (0)