mirror of
https://github.com/supabase/setup-cli.git
synced 2025-12-08 16:16:25 +00:00
Compare commits
12 Commits
ee3d7dc568
...
gh-pages
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a11fac2fe | ||
|
|
562d4d41dd | ||
|
|
5adad8121b | ||
|
|
81c1c5e51a | ||
|
|
a6e566c41f | ||
|
|
c0861c6efb | ||
|
|
cffb91a288 | ||
|
|
2bed722236 | ||
|
|
4e837d3e47 | ||
|
|
5b1cff838c | ||
|
|
20f0b4acc4 | ||
|
|
1529494aca |
83
docs/backups.md
Normal file
83
docs/backups.md
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# Backup your database
|
||||||
|
|
||||||
|
You can use the Supabase CLI to backup your Postgres database. The steps involve running a series of commands to dump roles, schema, and data separately.
|
||||||
|
Inside your repository, create a new file inside the `.github/workflows` folder called `backup.yml`. Copy the following snippet inside the file, and the action will run whenever a new PR is created.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
|
||||||
|
Never backup your data to a public repository.
|
||||||
|
|
||||||
|
## Backup action
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: 'backup-database'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # For example: postgresql://postgres:[YOUR-PASSWORD]@db.<ref>.supabase.co:5432/postgres
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- name: Backup roles
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f roles.sql --role-only
|
||||||
|
- name: Backup schema
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f schema.sql
|
||||||
|
- name: Backup data
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f data.sql --data-only --use-copy
|
||||||
|
```
|
||||||
|
## Periodic Backups Workflow
|
||||||
|
|
||||||
|
You can use the GitHub Action to run periodic backups of your database. In this example, the Action workflow is triggered by `push` and `pull_request` events on the `main` branch, manually via `workflow_dispatch`, and automatically at midnight every day due to the `schedule` event with a `cron` expression.
|
||||||
|
The workflow runs on the latest Ubuntu runner and requires write permissions to the repository's contents. It uses the Supabase CLI to dump the roles, schema, and data from your Supabase database, utilizing the `SUPABASE_DB_URL` environment variable that is securely stored in the GitHub secrets.
|
||||||
|
After the backup is complete, it auto-commits the changes to the repository using the `git-auto-commit-action`. This ensures that the latest backup is always available in your repository. The commit message for these automated commits is "Supabase backup".
|
||||||
|
This workflow provides an automated solution for maintaining regular backups of your Supabase database. It helps keep your data safe and enables easy restoration in case of any accidental data loss or corruption.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
|
||||||
|
Never backup your data to a public repository.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: Supa-backup
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # Runs every day at midnight
|
||||||
|
jobs:
|
||||||
|
run_db_backup:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
env:
|
||||||
|
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # For example: postgresql://postgres:[YOUR-PASSWORD]@db.<ref>.supabase.co:5432/postgres
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.head_ref }}
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- name: Backup roles
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f roles.sql --role-only
|
||||||
|
- name: Backup schema
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f schema.sql
|
||||||
|
- name: Backup data
|
||||||
|
run: supabase db dump --db-url "$supabase_db_url" -f data.sql --data-only --use-copy
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
commit_message: Supabase backup
|
||||||
|
```
|
||||||
|
|
||||||
|
## More resources
|
||||||
|
|
||||||
|
- Backing up and migrating your project: [Migrating and Upgrading](https://supabase.com/docs/guides/platform/migrating-and-upgrading-projects)
|
||||||
36
docs/generating-types.md
Normal file
36
docs/generating-types.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Generating Types
|
||||||
|
|
||||||
|
You can use the Supabase CLI to automatically generate Typescript definitions from your Postgres database. You can then pass these definitions to your `supabase-js` client and get end-to-end type safety across client, server, and database.
|
||||||
|
|
||||||
|
Inside your repository, create a new file inside the `.github/workflows` folder called `generate-types.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||||
|
|
||||||
|
## Verify types
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: 'generate-types'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- run: supabase init
|
||||||
|
- run: supabase db start
|
||||||
|
- name: Verify generated types match Postgres schema
|
||||||
|
run: |
|
||||||
|
supabase gen types typescript --local > schema.gen.ts
|
||||||
|
if ! git diff --ignore-space-at-eol --exit-code --quiet schema.gen.ts; then
|
||||||
|
echo "Detected uncommitted changes after build. See status below:"
|
||||||
|
git diff
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## More resources
|
||||||
|
|
||||||
|
- Using supabase-js with type definitions: [Typescript Support](https://supabase.com/docs/reference/javascript/typescript-support)
|
||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: supabase/setup-cli@v1
|
- uses: supabase/setup-cli@v1
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
- run: supabase init
|
- run: supabase init
|
||||||
- run: supabase db start
|
- run: supabase db start
|
||||||
|
|||||||
25
docs/migrations.md
Normal file
25
docs/migrations.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Managing database migrations
|
||||||
|
|
||||||
|
Migrations are programmatic changes to your database. They are usually checked into Git.
|
||||||
|
|
||||||
|
## Testing your migrations
|
||||||
|
|
||||||
|
Inside your repository, create a new file inside the `.github/workflows` folder called `test-migrations.yml`.
|
||||||
|
|
||||||
|
Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: 'test-migrations'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- run: supabase init
|
||||||
|
- run: supabase db start
|
||||||
|
```
|
||||||
59
docs/testing.md
Normal file
59
docs/testing.md
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# Automated testing
|
||||||
|
|
||||||
|
You can use the Supabase CLI to run automated tests.
|
||||||
|
|
||||||
|
## Testing your database
|
||||||
|
|
||||||
|
After you have [created unit tests](https://supabase.com/docs/guides/database/testing) for your database, you can use the GitHub Action to run the tests.
|
||||||
|
|
||||||
|
Inside your repository, create a new file inside the `.github/workflows` folder called `database-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: 'database-tests'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- run: supabase db start
|
||||||
|
- run: supabase test db
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing your Edge Functions
|
||||||
|
|
||||||
|
After you have [created unit tests](https://supabase.com/docs/guides/functions/unit-test) for your Edge Functions, you can use the GitHub Action to run the tests.
|
||||||
|
|
||||||
|
Inside your repository, create a new file inside the `.github/workflows` folder called `functions-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: 'functions-tests'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: supabase/setup-cli@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: latest
|
||||||
|
- run: supabase start
|
||||||
|
- run: deno test --allow-all deno-test.ts --env-file .env.local
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## More resources
|
||||||
|
|
||||||
|
- Learn more about the [pgTAP extension](https://supabase.com/docs/guides/database/extensions/pgtap) for database testing.
|
||||||
|
- Official pgTAP Documentation: [pgtap.org](https://pgtap.org/)
|
||||||
@@ -7,6 +7,7 @@ repo_url: https://github.com/supabase/supabase-github-action
|
|||||||
|
|
||||||
nav:
|
nav:
|
||||||
- Welcome: 'index.md'
|
- Welcome: 'index.md'
|
||||||
|
- Quickstart: 'migrations.md'
|
||||||
|
|
||||||
theme:
|
theme:
|
||||||
name: 'material'
|
name: 'material'
|
||||||
|
|||||||
Reference in New Issue
Block a user