This GitHub action workflow aims to help you to create a Supabase database definition types file in your project.
This workflow is a composite action:
- Generate database types with a built in command from supabase/setup-cli.
- Commit and push github actions to your repo are performed by the git-auto-commit action.
- Creating the pull request is performed by pull-request action.
If you don't have an existing GitHub Action workflow for your repository
- Create a folder
.github/workflows
if you don't have it already - Inside that folder, create a YAML file say
update-types.yml
- In the
update-types.yml
file, you can copy the example above and modify it to your usage. - You can choose to declare the
schedule
with a cron expression to run the job at a specified frequency e.g. every day once.
How to get Supabase Access Token
Go to https://app.supabase.com/account/tokens and get a token there.
Otherwise, you can get started by referring to to the example given and the input options available.
name: Update database types
on:
schedule:
- cron: '*/60 * * * *'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: lyqht/generate-supabase-db-types-github-action@main
with:
SUPABASE_REF_ID: ${{ secrets.SUPABASE_REF_ID }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
OUTPUT_PATH: db.types.ts
If your DB schema is kept up to date based on the migration SQL scripts within your project itself, you can configure the workflow to run based on any new SQL files pushed to your branch.
name: Update database types
on:
push:
branches: [ main ]
paths:
- '*.sql'
jobs:
build:
runs-on: ubuntu-latest
if: github.head_ref != 'supabot**'
steps:
- uses: lyqht/generate-supabase-db-types-github-action@main
with:
SUPABASE_REF_ID: ${{ secrets.SUPABASE_REF_ID }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
OUTPUT_PATH: db.types.ts
Please note that this will be a breaking change. The types generated from v0.1.0 could be different from that of v1.0.0, so you may need to modify your code quite a bit if you choose to migrate for fields of data types such as JSON
, Date
. However, v1.0.0
types follows what supabase recommends.
🔖 Here's an article that explains more in-depth the rationale & implementation of v0.1.0 of this GitHub action.
v0.1.0 relies on the openapi-typescript
library to generate types based on the OpenAPI specs that the Supabase endpoint offers.
v1.0.0 relies on supabase-cli
to generate the types using supabase, and these types are much more compatible to the supabasejs-v2
library.
You need to make the following changes in variables:
- No longer used:
SUPABASE_URL: ${{secrets.SUPABASE_URL }}
andSUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
- You have to add
SUPABASE_REF_ID: ${{ secrets.SUPABASE_REF_ID }}
, andSUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
Note that if your Supabase project is paused or deleted, this bot will only result in failed jobs.