Skip to content

Commit 8227186

Browse files
committed
chore: simplfy config for tmp db
Setting GUCs inside the bash file is complicated and is not easy to read. Use the `include 'init.conf` directive for simplifying the config file. It will also replace @tmpdir@ inside the config file.
1 parent eba662e commit 8227186

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

nix/withTmpDb.sh.in

+5-15
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,15 @@ PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER"
1515
# so we just modify the resulting postgresql.conf to avoid an error
1616
echo "dynamic_library_path='\$libdir:$(pwd)'" >> $PGDATA/postgresql.conf
1717
echo "extension_control_path='\$system:$(pwd)'" >> $PGDATA/postgresql.conf
18+
echo "include 'init.conf'" >> $PGDATA/postgresql.conf
1819

19-
options="-F -c listen_addresses=\"\" -k $PGDATA -c shared_preload_libraries=\"supautils\" -c wal_level=logical -c cron.database_name=postgres"
20+
cp ./test/init.conf $tmpdir/init.conf
2021

21-
reserved_roles="supabase_storage_admin, anon, reserved_but_not_yet_created, authenticator*"
22-
reserved_memberships="pg_read_server_files, pg_write_server_files, pg_execute_server_program, role_with_reserved_membership"
23-
privileged_extensions="autoinc, citext, hstore, sslinfo, insert_username, dict_xsyn, postgres_fdw, pageinspect"
24-
privileged_extensions_custom_scripts_path="$tmpdir/privileged_extensions_custom_scripts"
25-
privileged_role="privileged_role"
26-
privileged_role_allowed_configs="session_replication_role, pgrst.*, other.nested.*"
22+
sed -i "s|@TMPDIR@|$tmpdir|g" $tmpdir/init.conf
2723

28-
reserved_stuff_options="-c supautils.reserved_roles=\"$reserved_roles\" -c supautils.reserved_memberships=\"$reserved_memberships\" -c supautils.privileged_extensions=\"$privileged_extensions\" -c supautils.privileged_extensions_custom_scripts_path=\"$privileged_extensions_custom_scripts_path\" -c supautils.privileged_role=\"$privileged_role\" -c supautils.privileged_role_allowed_configs=\"$privileged_role_allowed_configs\""
29-
placeholder_stuff_options='-c supautils.placeholders="response.headers, another.placeholder" -c supautils.placeholders_disallowed_values="\"content-type\",\"x-special-header\",special-value"'
24+
options="-F -c listen_addresses=\"\" -k $PGDATA"
3025

31-
cexts_option='-c supautils.constrained_extensions="{\"adminpack\": { \"cpu\": 64}, \"cube\": { \"mem\": \"17 GB\"}, \"lo\": { \"disk\": \"100 GB\"}, \"amcheck\": { \"cpu\": 2, \"mem\": \"100 MB\", \"disk\": \"100 MB\"}}"'
32-
epos_option='-c supautils.extensions_parameter_overrides="{\"sslinfo\":{\"schema\":\"pg_catalog\"}}"'
33-
drop_trigger_grants_option='-c supautils.drop_trigger_grants="{\"privileged_role\":[\"allow_drop_triggers.my_table\"]}"'
34-
policy_grants_option='-c supautils.policy_grants="{\"privileged_role\":[\"allow_policies.my_table\",\"allow_policies.nonexistent_table\"]}"'
35-
36-
pg_ctl start -o "$options" -o "$reserved_stuff_options" -o "$placeholder_stuff_options" -o "$cexts_option" -o "$epos_option" -o "$drop_trigger_grants_option" -o "$policy_grants_option"
26+
pg_ctl start -o "$options"
3727

3828
# print notice when creating a TLE
3929
mkdir -p "$tmpdir/privileged_extensions_custom_scripts"

test/init.conf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
shared_preload_libraries='supautils'
2+
wal_level=logical
3+
4+
supautils.reserved_roles='supabase_storage_admin, anon, reserved_but_not_yet_created, authenticator*'
5+
supautils.reserved_memberships='pg_read_server_files,pg_write_server_files,pg_execute_server_program,role_with_reserved_membership'
6+
supautils.privileged_extensions='autoinc, citext, hstore, sslinfo, insert_username, dict_xsyn, postgres_fdw, pageinspect'
7+
supautils.constrained_extensions='{"adminpack": { "cpu": 64}, "cube": { "mem": "17 GB"}, "lo": { "disk": "100 GB"}, "amcheck": { "cpu": 2, "mem": "100 MB", "disk": "100 MB"}}'
8+
supautils.privileged_role='privileged_role'
9+
supautils.privileged_role_allowed_configs='session_replication_role, pgrst.*, other.nested.*'
10+
supautils.placeholders='response.headers, another.placeholder'
11+
supautils.placeholders_disallowed_values='"content-type","x-special-header",special-value'
12+
supautils.extensions_parameter_overrides='{"sslinfo":{"schema":"pg_catalog"}}'
13+
supautils.drop_trigger_grants='{"privileged_role":["allow_drop_triggers.my_table"]}'
14+
supautils.policy_grants='{"privileged_role":["allow_policies.my_table","allow_policies.nonexistent_table"]}'
15+
supautils.privileged_extensions_custom_scripts_path='@TMPDIR@/privileged_extensions_custom_scripts'

0 commit comments

Comments
 (0)