|
| 1 | +You can install extensions available on the database.dev registry using the dbdev in-database client. The dbdev client is itself an extension which you can install by following the instructions below. |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +Before you can install the dbdev extension into your database, ensure you have the following dependencies already installed: |
| 6 | + |
| 7 | +- [pg_tle](https://github.com/aws/pg_tle) |
| 8 | +- [pgsql-http](https://github.com/pramsey/pgsql-http) |
| 9 | + |
| 10 | +!!! note |
| 11 | + |
| 12 | + If you database is running on Supabase, the above dependencies are already installed. |
| 13 | + |
| 14 | +Run the following SQL to install the client: |
| 15 | + |
| 16 | +```sql |
| 17 | +create extension if not exists http with schema extensions; |
| 18 | +create extension if not exists pg_tle; |
| 19 | +select pgtle.uninstall_extension_if_exists('supabase-dbdev'); |
| 20 | +drop extension if exists "supabase-dbdev"; |
| 21 | +select |
| 22 | + pgtle.install_extension( |
| 23 | + 'supabase-dbdev', |
| 24 | + resp.contents ->> 'version', |
| 25 | + 'PostgreSQL package manager', |
| 26 | + resp.contents ->> 'sql' |
| 27 | + ) |
| 28 | +from http( |
| 29 | + ( |
| 30 | + 'GET', |
| 31 | + 'https://api.database.dev/rest/v1/' |
| 32 | + || 'package_versions?select=sql,version' |
| 33 | + || '&package_name=eq.supabase-dbdev' |
| 34 | + || '&order=version.desc' |
| 35 | + || '&limit=1', |
| 36 | + array[ |
| 37 | + ('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::http_header |
| 38 | + ], |
| 39 | + null, |
| 40 | + null |
| 41 | + ) |
| 42 | +) x, |
| 43 | +lateral ( |
| 44 | + select |
| 45 | + ((row_to_json(x) -> 'content') #>> '{}')::json -> 0 |
| 46 | +) resp(contents); |
| 47 | +create extension "supabase-dbdev"; |
| 48 | +select dbdev.install('supabase-dbdev'); |
| 49 | +drop extension if exists "supabase-dbdev"; |
| 50 | +create extension "supabase-dbdev"; |
| 51 | +``` |
| 52 | + |
| 53 | +## Use |
| 54 | + |
| 55 | +Once the client is installed, you an install a TLE available on database.dev by running SQL that looks like the following: |
| 56 | + |
| 57 | +```sql |
| 58 | +select dbdev.install(<extension_name>); |
| 59 | +create extension <extension_name> |
| 60 | + schema <schema> |
| 61 | + version <version>; |
| 62 | +``` |
| 63 | + |
| 64 | +For example, to install pg_headerkit version 1.0.0 in schema public run: |
| 65 | + |
| 66 | +```sql |
| 67 | +select dbdev.install('burggraf-pg_headerkit'); |
| 68 | +create extension "burggraf-pg_headerkit" |
| 69 | + schema 'public' |
| 70 | + version '1.0.0'; |
| 71 | +``` |
0 commit comments