Skip to content

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

Add example to keep type definitions up-to-date

Nick Mazuk368cacf5d80e
diff --git a/web/spec/supabase.yml b/web/spec/supabase.yml
index 3c266937660..63167ca5f3f 100644
--- a/web/spec/supabase.yml
+++ b/web/spec/supabase.yml
@@ -200,6 +200,57 @@ pages:
res.status(200).json(allOnlineUsers);
};
```
+
+ ### Update types automatically with a GitHub Action
+
+ To keep your type definitions in sync with your database, you can setup a GitHub action that will update the type definitions on a schedule.
+
+ First, add a script to your package.json to generate the types.
+
+ ```
+ "update-types": "npx openapi-typescript https://your-project.supabase.co/rest/v1/?apikey=your-anon-key --output types/supabase.ts"
+ ```
+
+ Next, in your repo, create the file `.github/workflows/update-types.yml`. Then, add the following snippet into this file to define the action. This action will create updated types, then if there was an update, it will commit the change to your repo.
+
+ ```yml
+ name: Update database types
+
+ on:
+ schedule:
+ # sets the action to run daily. You can modify this to run the action more or less freqently
+ - cron: '0 0 * * *'
+
+ jobs:
+ update:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ persist-credentials: false
+ fetch-depth: 0
+ - uses: actions/[email protected]
+ with:
+ node-version: 14
+ - run: npm run update-database-types
+ - name: check for file changes
+ id: git_status
+ run: |
+ echo "::set-output name=status::$(git status -s)"
+ - name: Commit files
+ if: ${{contains(steps.git_status.outputs.status, ' ')}}
+ run: |
+ git add types/database/index.ts
+ git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ git config --local user.name "github-actions[bot]"
+ git commit -m "Update database types" -a
+ - name: Push changes
+ if: ${{contains(steps.git_status.outputs.status, ' ')}}
+ uses: ad-m/github-push-action@master
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ branch: ${{ github.ref }}
+ ```
auth.signUp():
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.signUp'