From 061bf9a305352b36d4398fb6275334d2dd0b4526 Mon Sep 17 00:00:00 2001 From: Popa Vlad Date: Thu, 2 Nov 2023 13:37:36 +0200 Subject: [PATCH] fix: add backup and restore actions to bot --- .github/workflows/backup.yml | 40 +++++++++++++++++++++++++++++++++++ .github/workflows/restore.yml | 33 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/backup.yml create mode 100644 .github/workflows/restore.yml diff --git a/.github/workflows/backup.yml b/.github/workflows/backup.yml new file mode 100644 index 000000000..a2c72a6d5 --- /dev/null +++ b/.github/workflows/backup.yml @@ -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 diff --git a/.github/workflows/restore.yml b/.github/workflows/restore.yml new file mode 100644 index 000000000..b0abacd69 --- /dev/null +++ b/.github/workflows/restore.yml @@ -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