Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

quick pass through database guides

Paul Copplestonebf77d8deea0b
diff --git a/web/docs/guides/auth/auth-apple.mdx b/web/docs/guides/auth/auth-apple.mdx
index 36f6e639e7c..c31742bc60e 100644
--- a/web/docs/guides/auth/auth-apple.mdx
+++ b/web/docs/guides/auth/auth-apple.mdx
@@ -7,101 +7,104 @@ description: Add Apple OAuth to your Supabase project
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
-Setting up Apple logins for your application consists of six parts:
+Apple OAuth consists of six broad steps:
-* obtain an `App Id` with “Sign In with Apple” capabilities
-* obtain a `Services Id` - this will serve as the `client_id`
-* obtain a `secret key` that will be used to get our `client_secret`
-* generate the `client_secret` using the `secret key`
-* Add your `client id` and `client secret` keys to your [Supabase Project](https://supabase.io)
-* Add the login code to your [Supabase JS Client App](https://github.com/supabase/supabase-js)
+* Obtaining an `App Id` with “Sign In with Apple” capabilities.
+* Obtaining a `Services Id` - this will serve as the `client_id`.
+* Obtaining a `secret key` that will be used to get our `client_secret`.
+* Generating the `client_secret` using the `secret key`.
+* Add your `client id` and `client secret` keys to your [Supabase Project](https://supabase.io).
+* Add the login code to your [Supabase JS Client App](https://github.com/supabase/supabase-js).
## Steps
-### Log into your [Apple Developer Account](https://developer.apple.com)
+### Log into your Apple Developer Account
-- Go to [https://developer.apple.com](https://developer.apple.com)
-- Click on `Account` at the top right to log in
-
-Once logged into your *"Apple Deveoper Account"*:
+- Go to [https://developer.apple.com](https://developer.apple.com).
+- Click on `Account` at the top right to log in.
### Obtain an App Id with “Sign In with Apple” capabilities.
-- Go to "Certificates, Identifiers & Profiles"
-- Click on "Identifiers" at the left
-- Click on the + sign in the upper left next to “Identifiers”
-- Select "App IDs" and click "Continue"
-- Select type "App" and click "Continue"
-- Fill out your app information
- - App description
- - Bundle ID (Apple recommends reverse-domain name style, so if your domain is acme.com and your app is called roadrunner, use: "com.acme.roadrunner")
- - Scroll down and check "Sign In With Apple"
- - Click "Contine" at the top right
- - Click "Register" at the top right
+- Go to `Certificates, Identifiers & Profiles`.
+- Click on `Identifiers` at the left.
+- Click on the `+` sign in the upper left next to `Identifiers`.
+- Select `App IDs` and click `Continue`.
+- Select type `App` and click `Continue`.
+- Fill out your app information:
+ - App description.
+ - Bundle ID (Apple recommends reverse-domain name style, so if your domain is acme.com and your app is called roadrunner, use: "com.acme.roadrunner").
+ - Scroll down and check `Sign In With Apple`.
+ - Click `Continue` at the top right.
+ - Click `Register` at the top right.
### Obtain a Services ID
+
This will serve as the `cliend_id` when you make API calls to authenticate the user.
-- Go to Certificates, Identifiers & Profiles
-- Click on "Identifiers" at the left
-- Click on the + sign in the upper left next to “Identifiers”
-- Select "Services IDs" and click "Continue"
-- Fill out your information
- - App description
- - Bundle ID (you can't use the same Bundle ID from the previous step, but you can just add something to the beginning, such "app." to make it app.com.acme.roadrunner")
- - SAVE THIS ID -- this ID will become your "client_id" later
- - Click "Contine" at the top right
- - Click "Register" at the top right
+- Go to `Certificates, Identifiers & Profiles`.
+- Click on `Identifiers` at the left.
+- Click on the `+` sign in the upper left next to `Identifiers`.
+- Select `Services IDs` and click `Continue`.
+- Fill out your information:
+ - App description.
+ - Bundle ID (you can't use the same Bundle ID from the previous step, but you can just add something to the beginning, such "app." to make it app.com.acme.roadrunner").
+ - SAVE THIS ID -- this ID will become your "client_id" later.
+ - Click `Continue` at the top right.
+ - Click `Register` at the top right.
#### Configure your Services ID
-- Under "Identifiers", click on your newly-created Services ID
-- Check the box next to "Sign In With Apple" to enable it
-- Click "Configure" to the right
-- Make sure your newly created Bundle ID is selected under "Primary App ID"
-- Add your domain to the "Domains and Subdomains" box (do not add https://, just add the domain)
-- In the "Return URLs" box, type the callback URL of your app.
+- Under `Identifiers`, click on your newly-created Services ID.
+- Check the box next to `Sign In With Apple` to enable it.
+- Click `Configure` to the right.
+- Make sure your newly created Bundle ID is selected under `Primary App ID`
+- Add your domain to the `Domains and Subdomains` box (do not add `https://`, just add the domain).
+- In the `Return URLs` box, type the callback URL of your app.
- Your "Return URL" (OAuth Redirect URI) looks like this:
- `https://<project-ref>.supabase.co/auth/v1/callback`
- - where `https://<project-ref>.supabase.co` is your Supabase Project API URL
- - Go to your [Supasebase Project Dashboard](https://supabase.io)
- - Click on the "Settings" icon at the bottom of the left sidebar
- - Click on "API" in the list
- - Under Config / URL you'll find your API URL, you can click "Copy" to copy it to the clipboard
- - Now just add "/auth/v1/callback" to the end of that to get your full "OAuth Redirect URI"
- - Enter this in the "Return URLs" box
- - Click "Next" at the bottom right
-- Click "Done" at the bottom
-- Click "Contine" at the top right
-- Click "Save" at the top right
+ - where `https://<project-ref>.supabase.co` is your Supabase Project API URL.
+ - Go to your [Supasebase Project Dashboard](https://supabase.io).
+ - Click on the `Settings` icon at the bottom of the left sidebar.
+ - Click on `API` in the list.
+ - Under Config / URL you'll find your API URL, you can click `Copy` to copy it to the clipboard.
+ - Now just add `/auth/v1/callback` to the end of that to get your full "OAuth Redirect URI".
+ - Enter this in the `Return URLs` box.
+ - Click `Next` at the bottom right.
+- Click `Done` at the bottom.
+- Click `Continue` at the top right.
+- Click `Save` at the top right.
### Download your secret key
+
Now you'll need to download a "secret key" file from Apple that will be used to generate your `client_secret`.
-- Go to "Certificates, Identifiers & Profiles"
-- Click on "Keys" at the left
-- Click on the + sign in the upper left next to "Keys"
-- Enter a Key Name
-- Check "Sign In with Apple"
-- Click "Configure" to the right
-- Select your newly-created Services ID from the dropdown selector
-- Click "Save" at the top right
-- Click "Continue" at the top right
-- Click "Register" at the top right
-- Click "Download" at the top right
-- Save the downloaded file -- this contains your "secret key" that will be used to generate your `client_secret`
-- Click "Done" at the top right
-
-### Generate your `client_secret`
+- Go to `Certificates, Identifiers & Profiles`.
+- Click on `Keys` at the left.
+- Click on the `+` sign in the upper left next to `Keys`.
+- Enter a `Key Name`.
+- Check `Sign In with Apple`.
+- Click `Configure` to the right.
+- Select your newly-created Services ID from the dropdown selector.
+- Click `Save` at the top right.
+- Click `Continue` at the top right.
+- Click `Register` at the top right.
+- Click `Download` at the top right.
+- Save the downloaded file -- this contains your "secret key" that will be used to generate your `client_secret`.
+- Click `Done` at the top right.
+
+### Generate a `client_secret`
+
The "secret key" you downloaded is used to create the `client_secret` string you'll need to authenticate your users.
-According to the [Apple Docs](https://developer.apple.com/documentation/signinwithapplerestapi/generate_and_validate_tokens) it needs to be a JWT token encrypted using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm.
+According to the [Apple Docs](https://developer.apple.com/documentation/signinwithapplerestapi/generate_and_validate_tokens) it needs to be a JWT
+token encrypted using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm.
-At this time, the easiest way to generate this JWT token is with [Ruby](https://www.ruby-lang.org/en/). If you don't have Ruby installed, you can [Download Ruby Here](https://www.ruby-lang.org/en/downloads).
+At this time, the easiest way to generate this JWT token is with [Ruby](https://www.ruby-lang.org/en/).
+If you don't have Ruby installed, you can [Download Ruby Here](https://www.ruby-lang.org/en/downloads).
-- Install Ruby (or check to make sure it's installed on your system)
-- Install [ruby-jwt](https://github.com/jwt/ruby-jwt)
- - From the command line, run: `sudo gem install jwt`
+- Install Ruby (or check to make sure it's installed on your system).
+- Install [ruby-jwt](https://github.com/jwt/ruby-jwt).
+- From the command line, run: `sudo gem install jwt`.
Create the script below using a text editor: `secret_gen.rb`
@@ -135,46 +138,38 @@ token = JWT.encode(
puts token
```
-- Edit the `secret_gen.rb` file:
- - key_file = "Path to the private key you downloaded from Apple"
- - It should look like this: AuthKey_XXXXXXXXXX.p8
- - team_id = "Your Team ID"
- - This is found at the top right of the Apple Developer site (next to your name)
- - client_id = "The Service ID of the service you created"
- - This is the "Services ID" you created in the above step "Obtain a Services ID"
+1. Edit the `secret_gen.rb` file:
+ - `key_file` = "Path to the private key you downloaded from Apple". It should look like this: "AuthKey_XXXXXXXXXX.p8".
+ - `team_id` = "Your Team ID". This is found at the top right of the Apple Developer site (next to your name).
+ - `client_id` = "The Service ID of the service you created". This is the "Services ID" you created in the above step "Obtain a Services ID".
- If you've lost this ID, you can find it in the Apple Developer Site:
- - Go to "Certificates, Identifiers & Profiles"
- - Click "Identifiers" at the left
- - At the top right drop-down, select "Services IDs"
- - Find your Identifier in the list (i.e. app.com.acme.roadrunner)
- - key_id = "The Key ID of the private key"
- - This can be found in the name of your downloaded secret file (For a file named "AuthKey_XXXXXXXXXX.p8" your key_id is "XXXXXXXXXX")
+ - Go to `Certificates, Identifiers & Profiles`.
+ - Click `Identifiers` at the left.
+ - At the top right drop-down, select `Services IDs`.
+ - Find your Identifier in the list (i.e. app.com.acme.roadrunner).
+ - `key_id` = "The Key ID of the private key". This can be found in the name of your downloaded secret file (For a file named "AuthKey_XXXXXXXXXX.p8" your key_id is "XXXXXXXXXX").
- If you've lost this ID, you can find it in the Apple Developer Site:
- - Go to "Certificates, Identifiers & Profiles"
- - Click "Keys" at the left
- - Click on your newly-created key in the list
- - Look under "Key ID" to find your key_id
- - Once you've entered values for all 4 items (key_file, team_id, client_id, key_id) save the `secret_gen.rb` file
-- Generate your `client_secret`
- - From the command line, run: `ruby secret_gen.rb > client_secret.txt`
- - Your `client_secret` is now stored in this `client_secret.txt` file
-
-You should now have a `client_id` and `client_secret`
+ - Go to `Certificates, Identifiers & Profiles`.
+ - Click `Keys` at the left.
+ - Click on your newly-created key in the list.
+ - Look under `Key ID` to find your key_id.
+2. From the command line, run: `ruby secret_gen.rb > client_secret.txt`.
+3. Your `client_secret` is now stored in this `client_secret.txt` file.
-### Enter your Github Client ID and Client Secret into your Supabase Project
+### Add your OAuth credentials to Supabase
-- Go to your [Supasebase Project Dashboard](https://supabase.io)
-- In the left sidebar, click the "Authentication" icon (near the top)
-- Click "Settings" from the list to go to the "Authentication Settings" page
-- Enter the final (hosted) URL of your app under "Site URL" (this is important)
-- Under "External OAuth Providers" turn "Apple Enabled" to ON
-- Enter your `client_id` and `client_secret` saved in the previous steps
-- Click "Save"
+- Go to your [Supasebase Dashboard](https://supabase.io).
+- In the left sidebar, click the `Authentication` icon (near the top).
+- Click `Settings` from the list to go to the `Authentication Settings` page.
+- Enter the final (hosted) URL of your app under `Site URL` (this is important).
+- Under `External OAuth Providers` turn `Apple Enabled` to ON.
+- Enter your `client_id` and `client_secret` saved in the previous steps.
+- Click `Save`.
### Add login code to your client app
-The JavaScript client code is documented here: [Supabase OAuth Client Code](https://supabase.io/docs/reference/javascript/auth-signin#sign-in-using-third-party-providers)
+The JavaScript client code is documented in the [Supabase OAuth Reference](https://supabase.io/docs/reference/javascript/auth-signin#sign-in-using-third-party-providers).
```js
const { user, session, error } = await supabase.auth.signIn({
@@ -182,10 +177,10 @@ const { user, session, error } = await supabase.auth.signIn({
})
```
-Add this function which you can call from a button, link, or UI element.
+Add a function which you can call from a button, link, or UI element.
```js
-function signInWithGithub() {
+function signInWithApple() {
const { user, session, error } = await supabase.auth.signIn({
provider: 'apple'
});
@@ -202,10 +197,8 @@ function signout() {
## Resources
-* [Supabase Account - Free Tier OK](https://supabase.io)
-* [Supabase JS Client](https://github.com/supabase/supabase-js)
-* [Apple Developer Account](https://developer.apple.com)
-* [Ruby](https://www.ruby-lang.org/en/)
-* [ruby-jwt](https://github.com/jwt/ruby-jwt)
-* Thanks to [Janak Amarasena](https://medium.com/@janakda) who did all the heavy lifting in [How to configure Sign In with Apple](https://medium.com/identity-beyond-borders/how-to-configure-sign-in-with-apple-77c61e336003)
+* [Apple Developer Account](https://developer.apple.com).
+* [Ruby](https://www.ruby-lang.org/en/) Docs.
+* [ruby-jwt](https://github.com/jwt/ruby-jwt) library.
+* Thanks to [Janak Amarasena](https://medium.com/@janakda) who did all the heavy lifting in [How to configure Sign In with Apple](https://medium.com/identity-beyond-borders/how-to-configure-sign-in-with-apple-77c61e336003).
diff --git a/web/docs/guides/database/json.mdx b/web/docs/guides/database/json.mdx
index d3a442f30d8..0a8f44d2cf0 100644
--- a/web/docs/guides/database/json.mdx
+++ b/web/docs/guides/database/json.mdx
@@ -7,18 +7,12 @@ description: How to use JSON Data in PostgreSQL and the Supabase Javascript API.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
-## Description
+PostgreSQL supports [JSON functions and operators](https://www.postgresql.org/docs/12/functions-json.html) which gives flexiblity when storing data inside a database column.
-How to use JSON Data in PostgreSQL and the Supabase Javascript API
+PostgreSQL supports two types of JSON columns: `JSON` and `JSONB`. The recommended type is `JSONB`, so that's what we'll be using throughout this document.
-PostgreSQL supports [JSON functions and operators](https://www.postgresql.org/docs/12/functions-json.html) that can give you nearly unlimited flexiblity when storing data inside a database column. In this document you'll learn how to:
-
-* create database columns that store JSON data
-* insert JSON data into a database
-* query JSON data stored in a database
-
-PostgreSQL supports two types of JSON columns: JSON and JSONB. The recommended type is JSONB, so that's what we'll be using throughout this document.
+<!-- @TODO: I think we can explain this in our own words a bit more easily -->
> The json data type stores an exact copy of the input text, which processing functions must reparse on each execution; while jsonb data is stored in a decomposed binary format that makes it slightly slower to input due to added conversion overhead, but significantly faster to process, since no reparsing is needed. jsonb also supports indexing, which can be a significant advantage.
From: [PostgreSQL JSON types](https://www.postgresql.org/docs/12/datatype-json.html)
@@ -35,7 +29,8 @@ values={[
]}>
<TabItem value="UI">
-- Table Editor
+```bash
+1. Go to the Table Editor
- New Table
- Create a new table named `game_log`
- include primary key `id`, type `UUID`, default value `Automatically generate UUID`
@@ -48,6 +43,7 @@ values={[
- game_date type DATE
- home_team type TEXT
- visiting_team type TEXT
+```
</TabItem>
<TabItem value="SQL">
@@ -77,6 +73,7 @@ values={[
]}>
<TabItem value="UI">
+```bash
- Table Editor
- Select `game_log`
- Insert Row
@@ -85,7 +82,6 @@ values={[
- visiting_team: 'San Diego Padres'
- game_data: [COPY AND PASTE THE JSON BLOCK]
- ```js
{
"winning_pitcher": "Alzolay",
"losing_pitcher": "Johnson",
@@ -97,9 +93,9 @@ values={[
"visitors": [0,0,0,1,0,0,0,0,0],
"home": [0,0,0,1,2,0,3,0]}
}
- ```
-
+
- Save the new row
+```
</TabItem>
@@ -223,10 +219,11 @@ values={[
<TabItem value="SQL">
```sql
-SELECT game_data -> 'winning_pitcher' AS winning_pitcher FROM game_log;
+select game_data -> 'winning_pitcher' AS winning_pitcher
+from game_log;
```
-Resuls:
+Results:
| winning_pitcher |
| --------------- |
@@ -267,12 +264,12 @@ values={[
<TabItem value="SQL">
```sql
-SELECT
+select
visiting_team,
game_data -> 'final_score' -> 'visitors' -> 'runs' as visitors_runs,
home_team,
game_data -> 'final_score' -> 'home' -> 'runs' as home_runs
-FROM game_log;
+from game_log;
```
Results:
diff --git a/web/docs/guides/database/password-reset.mdx b/web/docs/guides/database/password-reset.mdx
index eede5c74f49..bd2e65eeae7 100644
--- a/web/docs/guides/database/password-reset.mdx
+++ b/web/docs/guides/database/password-reset.mdx
@@ -7,19 +7,18 @@ description: How to change your PostgreSQL database password.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
-## Description
+Your PostgreSQL database is the core of your Supabase project, so it's important that it has a strong, secure password at all times.
-How to change your PostgreSQL database password
-
-Your PostgreSQL database is the core of your Supabase project, so it's important to make sure it has a strong, secure password at all times. Changing the password is easy -- just make sure you choose a password that:
+Changing the password is easy, just make sure you choose a password that:
* **is very secure**
-* does not contain of the following symbols: **: / ? # ] [ @ ! $ & ' ( ) * + , ; =**
+* does not contain of the following symbols: `: / ? # ] [ @ ! $ & ' ( ) * + , ; =`
-These special symbols can conflict with connection string URLs or cause other problems, so it's best to avoid them. You can still make a secure password using a longer string or a randomized set of upper and lowercase letters and digits.
+Special symbols can conflict with connection string URLs, so it's best to avoid them. You can make a secure password using a longer string or a randomized set of upper and lowercase letters and digits.
### How do I create a secure password?
-- use a password manager to generate it, or
+
+- use a password manager to generate it
- make a long password (10 characters at least)
- don't use any common dictionary words
- use both upper and lower case characters, numbers, and any symbols not in the list above
@@ -55,6 +54,6 @@ Be sure to remember your password or store it in a secure place.
## Resources
-* [Supabase Account - Free Tier OK](https://supabase.io)
-* [PostgreSQL ALTER USER Documentation](https://www.postgresql.org/docs/12/sql-alteruser.html)
+- [Reference: Database Passwords](/docs/reference/postgres/database-passwords)
+- [PostgreSQL ALTER USER Documentation](https://www.postgresql.org/docs/12/sql-alteruser.html)
diff --git a/web/docs/guides/database/sql-to-api.mdx b/web/docs/guides/database/sql-to-api.mdx
index b646c160305..9448bb69ca6 100644
--- a/web/docs/guides/database/sql-to-api.mdx
+++ b/web/docs/guides/database/sql-to-api.mdx
@@ -7,6 +7,8 @@ description: Implementing common SQL patterns in the Javascript API
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
+<!-- @TODO: this one is a very daunting read on first attempt. Need to check what is the purpose of it? -->
+
Select a set of columns from a single table with where, order by, and limit clauses.
```sql