Skip to content

Update database schema #6

Update database schema

Update database schema #6

Workflow file for this run

name: Update database schema
on:
workflow_dispatch:
jobs:
update_schema:
runs-on: ubuntu-latest
env:
PGHOST: localhost
PGUSER: postgres
PGPASSWORD: password
PGDATABASE: postgres
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Install PostgreSQL 15 client
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-15
- name: Calculate yesterday’s date
id: date
run: echo "yesterday=$(date -d 'yesterday' +%Y-%m-%d)" >> $GITHUB_OUTPUT
- name: Download Postgres backup
run: |
curl -o backup.backup "https://pub-5200ce7fb4b64b5ea3b6b0b0f05cfcd5.r2.dev/${{ steps.date.outputs.yesterday }}_rating.backup"
- name: Restore backup
run: |
psql -U postgres -d postgres -c "DROP SCHEMA public CASCADE;"
pg_restore --dbname=postgres --username=postgres backup.backup
- name: Fetch database schema
run: |
pg_dump -h $PGHOST -U $PGUSER -d $PGDATABASE --schema-only --schema=public --schema=b > schema.sql
- name: Create PR
uses: peter-evans/create-pull-request@v7
with:
commit-message: update database schema to ${{ steps.date.outputs.yesterday }}
title: Update database schema
body: |
This PR updates the database schema based on the latest backup.
- Backup date: ${{ steps.date.outputs.yesterday }}
branch: update-schema
delete-branch: true