Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
fix: add backup and restore actions to bot
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomCracker committed Nov 2, 2023
1 parent 3ad77e5 commit 061bf9a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Database backup

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
run_db_backup:
runs-on: ubuntu-latest
permissions:
contents: write
env:
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # Encrypted Supabase DB URL

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: Database backup
33 changes: 33 additions & 0 deletions .github/workflows/restore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Database restore

on:
workflow_dispatch:
inputs:
restore-trigger:
description: 'Trigger database restore'
required: false
default: 'manual-restore'

jobs:
restore_db:
runs-on: ubuntu-latest
permissions:
contents: read
env:
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # Encrypted Supabase DB URL

steps:
- uses: actions/checkout@v3

- uses: supabase/setup-cli@v1
with:
version: latest

- name: Restore roles
run: supabase db restore --db-url "$supabase_db_url" -f roles.sql --role-only

- name: Restore schema
run: supabase db restore --db-url "$supabase_db_url" -f schema.sql

- name: Restore data
run: supabase db restore --db-url "$supabase_db_url" -f data.sql --data-only

0 comments on commit 061bf9a

Please sign in to comment.