Skip to content

Commit 7ef9daa

Browse files
committed
add dbdev client installation docs
1 parent 30e62bf commit 7ef9daa

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ dbdev is a package manager for Postgres [trusted language extensions](https://gi
2424
- dbdev CLI: a CLI for publishing TLEs to a registry.
2525
- dbdev client: an in-database client for installing TLEs from registries.
2626

27-
If you want to publish your own TLE, you will need the dbdev CLI. Follow its [installation instructions](install.md) to get started.
27+
If you want to publish your own TLE, you will need the dbdev CLI. Follow its [installation instructions](install-cli.md) to get started.
2828

2929
If you want to install an extension from the registry, you will need the SQL dbdev client. Follow its [installation instructions](https://database.dev/installer) to enable it in your database.

docs/install.md renamed to docs/install-cli.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ Alternatively, you can build the binary from source. You will need to have [Rust
5252

5353
If you have [cargo-install](https://doc.rust-lang.org/cargo/commands/cargo-install.html), you can perform all the above steps with a single command: `cargo install --git https://github.com/supabase/dbdev.git dbdev`.
5454

55-
Now you're ready to [publish your first package](publish.md).
55+
Now you're ready to [publish your first package](publish-extension.md).

docs/install-in-db-client.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
```

docs/publish.md renamed to docs/publish-extension.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mkdir my_first_tle
2323
cd my_first_tle
2424
```
2525

26-
Next create a `hello_world--0.0.1.sql` file, which will contain your extension's SQL objects. Add the following function definition to this file:
26+
Next create a `hello_world--0.0.1.sql` file, which will contain your extension's SQL objects. Add the following function definition to this file:
2727

2828
```sql
2929
create function greet(name text default 'world')
@@ -52,4 +52,4 @@ Now run the `dbdev publish` command to publish it.
5252
dbdev publish
5353
```
5454

55-
Your extension is now published to `database.dev` and visible under your account profile. You can visit your account profile from the account drop-down at the top right. Users can now install your extension using the [dbdev in-database client](https://database.dev/installer).
55+
Your extension is now published to `database.dev` and visible under your account profile. You can visit your account profile from the account drop-down at the top right. Users can now install your extension using the [dbdev in-database client](install-in-db-client.md).

mkdocs.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ repo_url: https://github.com/supabase/dbdev
77

88
nav:
99
- Welcome: 'index.md'
10-
- Install CLI: 'install.md'
11-
- Publish a Package: 'publish.md'
10+
- Install CLI: 'install-cli.md'
11+
- Publish a Package: 'publish-extension.md'
12+
- Install a Package: 'install-in-db-client.md'
1213
- Structure of a Postgres Extension: 'extension_structure.md'
1314

1415
theme:
@@ -18,6 +19,7 @@ theme:
1819
homepage: https://supabase.github.io/dbdev
1920
features:
2021
- navigation.expand
22+
- content.code.copy
2123
palette:
2224
primary: black
2325
accent: light green

0 commit comments

Comments
 (0)