Skip to content

Commit fd5e397

Browse files
committed
Merge remote-tracking branch 'origin/develop' into pcnc/pinned-nix-installer
2 parents 497f6e8 + d8e6308 commit fd5e397

21 files changed

+588
-20
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,23 @@ CI_start_postgres() {
8888

8989
swap_postgres_and_supabase_admin() {
9090
run_sql <<'EOSQL'
91+
alter database postgres connection limit 0;
92+
select pg_terminate_backend(pid) from pg_stat_activity where backend_type = 'client backend' and pid != pg_backend_pid();
93+
EOSQL
94+
run_sql <<'EOSQL'
95+
set statement_timeout = '300s';
9196
begin;
9297
create role supabase_tmp superuser;
9398
set session authorization supabase_tmp;
9499
100+
do $$
101+
begin
102+
if exists (select from pg_extension where extname = 'timescaledb') then
103+
execute(format('select %I.timescaledb_pre_restore()', (select pronamespace::regnamespace from pg_proc where proname = 'timescaledb_pre_restore')));
104+
end if;
105+
end
106+
$$;
107+
95108
do $$
96109
declare
97110
postgres_rolpassword text := (select rolpassword from pg_authid where rolname = 'postgres');
@@ -492,6 +505,19 @@ begin
492505
end
493506
$$;
494507
508+
do $$
509+
begin
510+
if exists (select from pg_extension where extname = 'timescaledb') then
511+
execute(format('select %I.timescaledb_post_restore()', (select pronamespace::regnamespace from pg_proc where proname = 'timescaledb_post_restore')));
512+
end if;
513+
end
514+
$$;
515+
516+
alter database postgres connection limit -1;
517+
518+
-- #incident-2024-09-12-project-upgrades-are-temporarily-disabled
519+
grant pg_read_all_data, pg_signal_backend to postgres;
520+
495521
set session authorization supabase_admin;
496522
drop role supabase_tmp;
497523
commit;

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ cleanup() {
127127
echo "Removing SUPERUSER grant from postgres"
128128
run_sql -c "ALTER USER postgres WITH NOSUPERUSER;"
129129

130+
echo "Resetting postgres database connection limit"
131+
run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"
132+
130133
if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
131134
echo "Unmounting data disk from ${MOUNT_POINT}"
132135
umount $MOUNT_POINT

ansible/files/envoy_config/lds.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ resources:
9393
local path = request_handle:headers():get(":path")
9494
request_handle
9595
:headers()
96-
:replace(":path", path:gsub("&=[^&]*", ""):gsub("?=[^&]*$", ""):gsub("?=[^&]*&", "?"))
97-
:replace(":path", path:gsub("&apikey=[^&]*", ""):gsub("?apikey=[^&]*$", ""):gsub("?apikey=[^&]*&", "?"))
96+
:replace(":path", path:gsub("&=[^&]*", ""):gsub("?=[^&]*$", ""):gsub("?=[^&]*&", "?"):gsub("&apikey=[^&]*", ""):gsub("?apikey=[^&]*$", ""):gsub("?apikey=[^&]*&", "?"))
9897
end
9998
remove_empty_key_query_parameters:
10099
inline_string: |-
@@ -103,7 +102,6 @@ resources:
103102
request_handle
104103
:headers()
105104
:replace(":path", path:gsub("&=[^&]*", ""):gsub("?=[^&]*$", ""):gsub("?=[^&]*&", "?"))
106-
107105
end
108106
- name: envoy.filters.http.compressor.brotli
109107
typed_config:
@@ -290,7 +288,7 @@ resources:
290288
envoy.filters.http.lua:
291289
'@type': >-
292290
type.googleapis.com/envoy.extensions.filters.http.lua.v3.LuaPerRoute
293-
name: remove_apikey_and_empty_key_query_parameter
291+
name: remove_apikey_and_empty_key_query_parameters
294292
- match:
295293
prefix: /rest/v1/
296294
request_headers_to_remove:
@@ -303,7 +301,7 @@ resources:
303301
envoy.filters.http.lua:
304302
'@type': >-
305303
type.googleapis.com/envoy.extensions.filters.http.lua.v3.LuaPerRoute
306-
name: remove_empty_key_query_parameter
304+
name: remove_empty_key_query_parameters
307305
- match:
308306
prefix: /rest-admin/v1/
309307
query_parameters:
@@ -414,3 +412,4 @@ resources:
414412
filename: /etc/envoy/fullChain.pem
415413
private_key:
416414
filename: /etc/envoy/privKey.pem
415+

common-nix.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.6.1.120"
1+
postgres-version = "15.6.1.121"

flake.nix

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,37 @@
4646
#This variable works the same as 'oriole_pkgs' but builds using the upstream
4747
#nixpkgs builds of postgresql 15 and 16 + the overlays listed below
4848
pkgs = import nixpkgs {
49-
config = { allowUnfree = true; };
49+
config = {
50+
allowUnfree = true;
51+
permittedInsecurePackages = [
52+
"v8-9.7.106.18"
53+
];
54+
};
5055
inherit system;
5156
overlays = [
5257
# NOTE (aseipp): add any needed overlays here. in theory we could
5358
# pull them from the overlays/ directory automatically, but we don't
5459
# want to have an arbitrary order, since it might matter. being
5560
# explicit is better.
61+
(final: prev: {
62+
postgresql = final.callPackage ./nix/postgresql/default.nix {
63+
inherit (final) lib;
64+
inherit (final) stdenv;
65+
inherit (final) fetchurl;
66+
inherit (final) makeWrapper;
67+
inherit (final) callPackage;
68+
};
69+
})
5670
(import ./nix/overlays/cargo-pgrx-0-11-3.nix)
5771
# (import ./nix/overlays/postgis.nix)
5872
#(import ./nix/overlays/gdal-small.nix)
5973

6074
];
6175
};
62-
76+
postgresql_15 = pkgs.postgresql.postgresql_15;
77+
postgresql = pkgs.postgresql.postgresql_15;
6378
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
64-
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { };
79+
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { inherit postgresql; };
6580

6681
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
6782
# These are maintained upstream and can easily be used here just by
@@ -128,7 +143,10 @@
128143
#this var is a convenience setting to import the orioledb patched version of postgresql
129144
postgresql_orioledb_16 = oriole_pkgs.postgresql_orioledb_16;
130145
#postgis_override = pkgs.postgis_override;
131-
146+
getPostgresqlPackage = version:
147+
pkgs.postgresql."postgresql_${version}";
148+
#we will add supported versions to this list in the future
149+
supportedVersions = [ "15" ];
132150
# Create a 'receipt' file for a given postgresql package. This is a way
133151
# of adding a bit of metadata to the package, which can be used by other
134152
# tools to inspect what the contents of the install are: the PSQL
@@ -170,7 +188,7 @@
170188
in map (path: pkgs.callPackage path { inherit postgresql; }) orioledbExtension;
171189

172190
makeOurPostgresPkgs = version:
173-
let postgresql = pkgs."postgresql_${version}";
191+
let postgresql = getPostgresqlPackage version;
174192
in map (path: pkgs.callPackage path { inherit postgresql; }) ourExtensions;
175193

176194
# Create an attrset that contains all the extensions included in a server for the orioledb version of postgresql + extension.
@@ -202,7 +220,7 @@
202220
# basis for building extensions, etc.
203221
makePostgresBin = version:
204222
let
205-
postgresql = pkgs."postgresql_${version}";
223+
postgresql = getPostgresqlPackage version;
206224
upstreamExts = map
207225
(ext: {
208226
name = postgresql.pkgs."${ext}".pname;
@@ -273,6 +291,30 @@
273291
sfcgal = sfcgal;
274292
pg_regress = pg_regress;
275293
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
294+
postgresql_15 = pkgs.postgresql_15;
295+
296+
postgresql_15_src = pkgs.stdenv.mkDerivation {
297+
pname = "postgresql-15-src";
298+
version = pkgs.postgresql_15.version;
299+
300+
src = pkgs.postgresql_15.src;
301+
302+
nativeBuildInputs = [ pkgs.bzip2 ];
303+
304+
phases = [ "unpackPhase" "installPhase" ];
305+
306+
installPhase = ''
307+
mkdir -p $out
308+
cp -r . $out
309+
'';
310+
311+
meta = with pkgs.lib; {
312+
description = "PostgreSQL 15 source files";
313+
homepage = "https://www.postgresql.org/";
314+
license = licenses.postgresql;
315+
platforms = platforms.all;
316+
};
317+
};
276318
# Start a version of the server.
277319
start-server =
278320
let
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
-- migrate:up
22

33
-- update owner for auth.uid, auth.role and auth.email functions
4-
ALTER FUNCTION auth.uid owner to supabase_auth_admin;
5-
ALTER FUNCTION auth.role owner to supabase_auth_admin;
6-
ALTER FUNCTION auth.email owner to supabase_auth_admin;
4+
DO $$
5+
BEGIN
6+
ALTER FUNCTION auth.uid owner to supabase_auth_admin;
7+
EXCEPTION WHEN OTHERS THEN
8+
RAISE WARNING 'Error encountered when changing owner of auth.uid to supabase_auth_admin';
9+
END $$;
710

11+
DO $$
12+
BEGIN
13+
ALTER FUNCTION auth.role owner to supabase_auth_admin;
14+
EXCEPTION WHEN OTHERS THEN
15+
RAISE WARNING 'Error encountered when changing owner of auth.role to supabase_auth_admin';
16+
END $$;
17+
18+
DO $$
19+
BEGIN
20+
ALTER FUNCTION auth.email owner to supabase_auth_admin;
21+
EXCEPTION WHEN OTHERS THEN
22+
RAISE WARNING 'Error encountered when changing owner of auth.email to supabase_auth_admin';
23+
END $$;
824
-- migrate:down

nix/ext/pg_graphql.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ buildPgrxExtension_0_11_3 rec {
1616
buildInputs = [ postgresql ];
1717

1818
CARGO="${cargo}/bin/cargo";
19+
#darwin env needs PGPORT to be unique for build to not clash with other pgrx extensions
1920
env = lib.optionalAttrs stdenv.isDarwin {
2021
POSTGRES_LIB = "${postgresql}/lib";
2122
RUSTFLAGS = "-C link-arg=-undefined -C link-arg=dynamic_lookup";
23+
PGPORT = "5434";
2224
};
2325
cargoHash = "sha256-WkHufMw8OvinMRYd06ZJACnVvY9OLi069nCgq3LSmMY=";
2426

nix/ext/pg_jsonschema.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ buildPgrxExtension_0_11_3 rec {
1919

2020
previousVersions = ["0.3.0" "0.2.0" "0.1.4" "0.1.4" "0.1.2" "0.1.1" "0.1.0"];
2121
CARGO="${cargo}/bin/cargo";
22+
#darwin env needs PGPORT to be unique for build to not clash with other pgrx extensions
2223
env = lib.optionalAttrs stdenv.isDarwin {
2324
POSTGRES_LIB = "${postgresql}/lib";
2425
RUSTFLAGS = "-C link-arg=-undefined -C link-arg=dynamic_lookup";
26+
PGPORT = "5433";
2527
};
2628
cargoHash = "sha256-VcS+efMDppofuFW2zNrhhsbC28By3lYekDFquHPta2g=";
2729

nix/postgresql/15.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import ./generic.nix {
2+
version = "15.6";
3+
hash = "sha256-hFUUbtnGnJOlfelUrq0DAsr60DXCskIXXWqh4X68svs=";
4+
}

nix/postgresql/default.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
self:
2+
let
3+
#adapted from the postgresql nixpkgs package
4+
versions = {
5+
postgresql_15 = ./15.nix;
6+
};
7+
8+
mkAttributes = jitSupport:
9+
self.lib.mapAttrs' (version: path:
10+
let
11+
attrName = if jitSupport then "${version}_jit" else version;
12+
in
13+
self.lib.nameValuePair attrName (import path {
14+
inherit jitSupport self;
15+
})
16+
) versions;
17+
18+
in
19+
# variations without and with JIT
20+
(mkAttributes false) // (mkAttributes true)

0 commit comments

Comments
 (0)