|
| 1 | +-- A list of extensions which are allowed in the requires key of the control file |
| 2 | +create table app.allowed_extensions ( |
| 3 | + name text primary key |
| 4 | +); |
| 5 | + |
| 6 | +insert into app.allowed_extensions (name) |
| 7 | +values |
| 8 | +-- extensions available on Supabase |
| 9 | + ('citext'), |
| 10 | + ('pg_cron'), |
| 11 | + ('pg_graphql'), |
| 12 | + ('pg_stat_statements'), |
| 13 | + ('pg_trgm'), |
| 14 | + ('pg_crypto'), |
| 15 | + ('pg_jwt'), |
| 16 | + ('pg_sodium'), |
| 17 | + ('plpgsql'), |
| 18 | + ('uuid-ossp'), |
| 19 | + ('address_standardizer'), |
| 20 | + ('address_standardizer_data_us'), |
| 21 | + ('autoinc'), |
| 22 | + ('bloom'), |
| 23 | + ('btree_gin'), |
| 24 | + ('btree_gist'), |
| 25 | + ('cube'), |
| 26 | + ('dblink'), |
| 27 | + ('dict_int'), |
| 28 | + ('dict_xsyn'), |
| 29 | + ('earthdistance'), |
| 30 | + ('fuzzystrmatch'), |
| 31 | + ('hstore'), |
| 32 | + ('http'), |
| 33 | + ('hypopg'), |
| 34 | + ('insert_username'), |
| 35 | + ('intarray'), |
| 36 | + ('isn'), |
| 37 | + ('ltree'), |
| 38 | + ('moddatetime'), |
| 39 | + ('pg_hashids'), |
| 40 | + ('pg_jsonschema'), |
| 41 | + ('pg_net'), |
| 42 | + ('pg_repack'), |
| 43 | + ('pg_stat_monitor'), |
| 44 | + ('pg_walinspect'), |
| 45 | + ('pgaudit'), |
| 46 | + ('pgroonga'), |
| 47 | + ('pgroonga_database'), |
| 48 | + ('pgrouting'), |
| 49 | + ('pgrowlocks'), |
| 50 | + ('pgtap'), |
| 51 | + ('plcoffee'), |
| 52 | + ('pljava'), |
| 53 | + ('plls'), |
| 54 | + ('plpgsql_check'), |
| 55 | + ('plv8'), |
| 56 | + ('postgis'), |
| 57 | + ('postgis_raster'), |
| 58 | + ('postgis_sfcgal'), |
| 59 | + ('postgis_tiger_geocoder'), |
| 60 | + ('postgis_topology'), |
| 61 | + ('postgres_fdw'), |
| 62 | + ('refint'), |
| 63 | + ('rum'), |
| 64 | + ('seg'), |
| 65 | + ('sslinfo'), |
| 66 | + ('supautils'), |
| 67 | + ('tablefunc'), |
| 68 | + ('tcn'), |
| 69 | + ('timescaledb'), |
| 70 | + ('tsm_system_rows'), |
| 71 | + ('tsm_system_time'), |
| 72 | + ('unaccent'), |
| 73 | + ('vector'), |
| 74 | + ('wrappers'), |
| 75 | + |
| 76 | +-- extensions available on AWS (except those already in Supabase) |
| 77 | +-- full list here: https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-extensions.html |
| 78 | + ('amcheck'), |
| 79 | + ('aws_commons'), |
| 80 | + ('aws_lambda'), |
| 81 | + ('aws_s3'), |
| 82 | + ('bool_plperl'), |
| 83 | + ('decoder_raw'), |
| 84 | + ('h3-pg'), |
| 85 | + ('hll'), |
| 86 | + ('hstore_plperl'), |
| 87 | + ('intagg'), |
| 88 | + ('ip4r'), |
| 89 | + ('jsonb_plperl'), |
| 90 | + ('lo'), |
| 91 | + ('log_fdw'), |
| 92 | + ('mysql_fdw'), |
| 93 | + ('old_snapshot'), |
| 94 | + ('oracle_fdw'), |
| 95 | + ('orafce'), |
| 96 | + ('pageinspect'), |
| 97 | + ('pg_bigm'), |
| 98 | + ('pg_buffercache'), |
| 99 | + ('pg_freespacemap'), |
| 100 | + ('pg_hint_plan'), |
| 101 | + ('pg_partman'), |
| 102 | + ('pg_prewarm'), |
| 103 | + ('pg_proctab'), |
| 104 | + ('pg_similarity'), |
| 105 | + ('pg_tle'), |
| 106 | + ('pg_transport'), |
| 107 | + ('pg_visibility'), |
| 108 | + ('pgcrypto'), |
| 109 | + ('pgstattuple'), |
| 110 | + ('pgvector'), |
| 111 | + ('plperl'), |
| 112 | + ('plprofiler'), |
| 113 | + ('plrust'), |
| 114 | + ('pltcl'), |
| 115 | + ('prefix'), |
| 116 | + ('rdkit'), |
| 117 | + ('rds_tools'), |
| 118 | + ('tds_fdw'), |
| 119 | + ('test_parser'), |
| 120 | + ('wal2json'); |
| 121 | + |
| 122 | +grant insert (partial_name, handle, control_description, control_relocatable, control_requires) |
| 123 | + on app.packages |
| 124 | + to authenticated; |
| 125 | + |
| 126 | +grant update (control_description, control_relocatable, control_requires) |
| 127 | + on app.packages |
| 128 | + to authenticated; |
| 129 | + |
| 130 | +create or replace function public.publish_package( |
| 131 | + package_name app.valid_name, |
| 132 | + package_description varchar(1000), |
| 133 | + relocatable bool default false, |
| 134 | + requires text[] default '{}' |
| 135 | +) |
| 136 | + returns void |
| 137 | + language plpgsql |
| 138 | +as $$ |
| 139 | +declare |
| 140 | + account app.accounts = account from app.accounts account where id = auth.uid(); |
| 141 | + require text; |
| 142 | +begin |
| 143 | + if account.handle is null then |
| 144 | + raise exception 'user not logged in'; |
| 145 | + end if; |
| 146 | + |
| 147 | + foreach require in array requires |
| 148 | + loop |
| 149 | + if not exists ( |
| 150 | + select true |
| 151 | + from app.allowed_extensions |
| 152 | + where |
| 153 | + name = require |
| 154 | + ) then |
| 155 | + raise exception '`requires` in the control file can''t have `%` in it', require; |
| 156 | + end if; |
| 157 | + end loop; |
| 158 | + |
| 159 | + insert into app.packages(handle, partial_name, control_description, control_relocatable, control_requires) |
| 160 | + values (account.handle, package_name, package_description, relocatable, requires) |
| 161 | + on conflict on constraint packages_handle_partial_name_key |
| 162 | + do update |
| 163 | + set control_description = excluded.control_description, |
| 164 | + control_relocatable = excluded.control_relocatable, |
| 165 | + control_requires = excluded.control_requires; |
| 166 | +end; |
| 167 | +$$; |
0 commit comments