Skip to content

Commit 7af56db

Browse files
authored
Merge branch 'develop' into sam/wal-g-3
2 parents 1e1cb06 + 44df10e commit 7af56db

18 files changed

+331
-190
lines changed

Dockerfile-15

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ARG rum_release=1.3.13
2424
ARG pg_hashids_release=cd0e1b31d52b394a0df64079406a14a4f7387cd6
2525
ARG libsodium_release=1.0.18
2626
ARG pgsodium_release=3.1.6
27-
ARG pg_graphql_release=1.5.1
27+
ARG pg_graphql_release=1.5.11
2828
ARG pg_stat_monitor_release=1.1.1
2929
ARG pg_jsonschema_release=0.1.4
3030
ARG pg_repack_release=1.4.8

Dockerfile-orioledb-17

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ARG rum_release=1.3.13
2424
ARG pg_hashids_release=cd0e1b31d52b394a0df64079406a14a4f7387cd6
2525
ARG libsodium_release=1.0.18
2626
ARG pgsodium_release=3.1.6
27-
ARG pg_graphql_release=1.5.1
27+
ARG pg_graphql_release=1.5.11
2828
ARG pg_stat_monitor_release=1.1.1
2929
ARG pg_jsonschema_release=0.1.4
3030
ARG pg_repack_release=1.4.8

ansible/files/admin_api_scripts/grow_fs.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ if pgrep resizefs; then
99
exit 1
1010
fi
1111

12+
# Parses the output of lsblk to get the root partition number
13+
# Example output:
14+
# NAME MOUNTPOINT
15+
# nvme0n1
16+
# ├─nvme0n1p1 /boot
17+
# └─nvme0n1p3 /
18+
# nvme1n1 /data
19+
#
20+
# Resulting in:
21+
# └─nvme0n1p3 / -> nvme0n1p3 -> 3
22+
ROOT_PARTITION_NUMBER=$(lsblk -no NAME,MOUNTPOINT | grep ' /$' | awk '{print $1;}' | sed 's/.*nvme[0-9]n[0-9]p//g')
23+
24+
if ! [[ "$ROOT_PARTITION_NUMBER" =~ ^[0-9]+$ ]]; then
25+
echo "Error: ROOT_PARTITION_NUMBER is not a valid number: $ROOT_PARTITION_NUMBER"
26+
exit 1
27+
fi
28+
1229
if [ -b /dev/nvme1n1 ] ; then
1330
if [[ "${VOLUME_TYPE}" == "data" ]]; then
1431
resize2fs /dev/nvme1n1
1532

1633
elif [[ "${VOLUME_TYPE}" == "root" ]] ; then
1734
PLACEHOLDER_FL=/home/ubuntu/50M_PLACEHOLDER
1835
rm -f "${PLACEHOLDER_FL}" || true
19-
growpart /dev/nvme0n1 2
20-
resize2fs /dev/nvme0n1p2
36+
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
37+
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
2138
if [[ ! -f "${PLACEHOLDER_FL}" ]] ; then
2239
fallocate -l50M "${PLACEHOLDER_FL}"
2340
fi
@@ -26,7 +43,7 @@ if [ -b /dev/nvme1n1 ] ; then
2643
exit 1
2744
fi
2845
else
29-
growpart /dev/nvme0n1 2
30-
resize2fs /dev/nvme0n1p2
46+
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
47+
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
3148
fi
3249
echo "Done resizing disk"

ebssurrogate/scripts/qemu-bootstrap-nix.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function waitfor_boot_finished {
2222
}
2323

2424
function install_packages {
25-
apt-get update && sudo apt-get install software-properties-common e2fsprogs -y
25+
apt-get update && sudo apt-get install software-properties-common e2fsprogs nfs-common -y
2626
add-apt-repository --yes --update ppa:ansible/ansible && sudo apt-get install ansible -y
2727
ansible-galaxy collection install community.general
2828
}
@@ -143,4 +143,6 @@ function clean_system {
143143

144144
install_nix
145145
execute_stage2_playbook
146+
# we do not want to ship an initialized DB as this is performed as needed
147+
rm -rf /data/pgdata
146148
cloud-init clean --logs

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
buildPgrxExtension_0_12_6 = prev.buildPgrxExtension.override {
6969
cargo-pgrx = final.cargo-pgrx.cargo-pgrx_0_12_6;
7070
};
71+
72+
buildPgrxExtension_0_12_9 = prev.buildPgrxExtension.override {
73+
cargo-pgrx = final.cargo-pgrx.cargo-pgrx_0_12_9;
74+
};
75+
7176
})
7277
(final: prev: {
7378
postgresql = final.callPackage ./nix/postgresql/default.nix {
@@ -395,6 +400,7 @@
395400
supabase-groonga = supabase-groonga;
396401
cargo-pgrx_0_11_3 = pkgs.cargo-pgrx.cargo-pgrx_0_11_3;
397402
cargo-pgrx_0_12_6 = pkgs.cargo-pgrx.cargo-pgrx_0_12_6;
403+
cargo-pgrx_0_12_9 = pkgs.cargo-pgrx.cargo-pgrx_0_12_9;
398404
# PostgreSQL versions.
399405
psql_15 = postgresVersions.psql_15;
400406
psql_orioledb-17 = postgresVersions.psql_orioledb-17;

migrations/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ Additionally, [supabase/postgres](https://github.com/supabase/postgres/blob/deve
7878

7979
### Add a Migration
8080

81+
First, start a local postgres server and apply the migrations
82+
8183
```shell
8284
# Start the database server
83-
docker-compose up
85+
nix run .#dbmate-tool -- --version 15 --flake-url "."
8486

8587
# create a new migration
88+
nix develop
8689
dbmate new '<some message>'
8790
```
8891

89-
Then, populate the migration at `./db/migrations/xxxxxxxxx_<some_message>` and make sure it execute sucessfully with
92+
Then, execute the migration at `./db/migrations/xxxxxxxxx_<some_message>` and make sure it runs sucessfully with
9093

9194
```shell
9295
dbmate up

migrations/db/migrations/20221207154255_create_pgsodium_and_vault.sql

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,44 @@ DECLARE
55
pgsodium_exists boolean;
66
vault_exists boolean;
77
BEGIN
8-
pgsodium_exists = (
9-
select count(*) = 1
10-
from pg_available_extensions
11-
where name = 'pgsodium'
12-
and default_version in ('3.1.6', '3.1.7', '3.1.8', '3.1.9')
13-
);
14-
15-
vault_exists = (
8+
IF EXISTS (SELECT FROM pg_available_extensions WHERE name = 'supabase_vault' AND default_version != '0.2.8') THEN
9+
CREATE EXTENSION IF NOT EXISTS supabase_vault;
10+
11+
-- for some reason extension custom scripts aren't run during AMI build, so
12+
-- we manually run it here
13+
GRANT USAGE ON SCHEMA vault TO postgres WITH GRANT OPTION;
14+
GRANT SELECT, DELETE ON vault.secrets, vault.decrypted_secrets TO postgres WITH GRANT OPTION;
15+
GRANT EXECUTE ON FUNCTION vault.create_secret, vault.update_secret, vault._crypto_aead_det_decrypt TO postgres WITH GRANT OPTION;
16+
ELSE
17+
pgsodium_exists = (
1618
select count(*) = 1
1719
from pg_available_extensions
18-
where name = 'supabase_vault'
19-
);
20-
21-
IF pgsodium_exists
22-
THEN
23-
create extension if not exists pgsodium;
24-
25-
grant pgsodium_keyiduser to postgres with admin option;
26-
grant pgsodium_keyholder to postgres with admin option;
27-
grant pgsodium_keymaker to postgres with admin option;
28-
29-
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
30-
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
31-
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
32-
33-
IF vault_exists
20+
where name = 'pgsodium'
21+
and default_version in ('3.1.6', '3.1.7', '3.1.8', '3.1.9')
22+
);
23+
24+
vault_exists = (
25+
select count(*) = 1
26+
from pg_available_extensions
27+
where name = 'supabase_vault'
28+
);
29+
30+
IF pgsodium_exists
3431
THEN
35-
create extension if not exists supabase_vault;
32+
create extension if not exists pgsodium;
33+
34+
grant pgsodium_keyiduser to postgres with admin option;
35+
grant pgsodium_keyholder to postgres with admin option;
36+
grant pgsodium_keymaker to postgres with admin option;
37+
38+
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
39+
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
40+
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
41+
42+
IF vault_exists
43+
THEN
44+
create extension if not exists supabase_vault;
45+
END IF;
3646
END IF;
3747
END IF;
3848
END $$;

migrations/db/migrations/20230529180330_alter_api_roles_for_inherit.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ ALTER ROLE authenticated inherit;
44
ALTER ROLE anon inherit;
55
ALTER ROLE service_role inherit;
66

7-
GRANT pgsodium_keyholder to service_role;
7+
DO $$
8+
BEGIN
9+
IF EXISTS (SELECT FROM pg_roles WHERE rolname = 'pgsodium_keyholder') THEN
10+
GRANT pgsodium_keyholder to service_role;
11+
END IF;
12+
END $$;
813

914
-- migrate:down
1015

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- migrate:up
2+
do $$
3+
declare
4+
ext_schema text;
5+
extensions_schema_exists boolean;
6+
begin
7+
-- check if the "extensions" schema exists
8+
select exists (
9+
select 1 from pg_namespace where nspname = 'extensions'
10+
) into extensions_schema_exists;
11+
12+
if extensions_schema_exists then
13+
-- check if the "orioledb" extension is in the "public" schema
14+
select nspname into ext_schema
15+
from pg_extension e
16+
join pg_namespace n on e.extnamespace = n.oid
17+
where extname = 'orioledb';
18+
19+
if ext_schema = 'public' then
20+
execute 'alter extension orioledb set schema extensions';
21+
end if;
22+
end if;
23+
end $$;
24+
25+
-- migrate:down
26+
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
-- migrate:up
2-
CREATE OR REPLACE FUNCTION pgsodium.mask_role(masked_role regrole, source_name text, view_name text)
3-
RETURNS void
4-
LANGUAGE plpgsql
5-
SECURITY DEFINER
6-
SET search_path TO ''
7-
AS $function$
2+
3+
DO $$
84
BEGIN
9-
EXECUTE format(
10-
'GRANT SELECT ON pgsodium.key TO %s',
11-
masked_role);
5+
IF EXISTS (SELECT FROM pg_extension WHERE extname = 'pgsodium') THEN
6+
CREATE OR REPLACE FUNCTION pgsodium.mask_role(masked_role regrole, source_name text, view_name text)
7+
RETURNS void
8+
LANGUAGE plpgsql
9+
SECURITY DEFINER
10+
SET search_path TO ''
11+
AS $function$
12+
BEGIN
13+
EXECUTE format(
14+
'GRANT SELECT ON pgsodium.key TO %s',
15+
masked_role);
1216

13-
EXECUTE format(
14-
'GRANT pgsodium_keyiduser, pgsodium_keyholder TO %s',
15-
masked_role);
17+
EXECUTE format(
18+
'GRANT pgsodium_keyiduser, pgsodium_keyholder TO %s',
19+
masked_role);
1620

17-
EXECUTE format(
18-
'GRANT ALL ON %I TO %s',
19-
view_name,
20-
masked_role);
21-
RETURN;
22-
END
23-
$function$;
21+
EXECUTE format(
22+
'GRANT ALL ON %I TO %s',
23+
view_name,
24+
masked_role);
25+
RETURN;
26+
END
27+
$function$;
28+
END IF;
29+
END $$;
2430

2531
-- migrate:down

0 commit comments

Comments
 (0)