Skip to content

Commit

Permalink
Merge pull request #2 from maii-chgk/image
Browse files Browse the repository at this point in the history
 create an action to update db schema
  • Loading branch information
razumau authored Sep 22, 2024
2 parents 4107577 + 651d08c commit ccac195
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
Expand All @@ -26,7 +27,7 @@ jobs:
- name: Create Dockerfile
run: |
cat << EOF > Dockerfile
FROM postgres:15
FROM --platform=\$BUILDPLATFORM postgres:15
RUN apt-get update && apt-get install -y wget
Expand Down Expand Up @@ -72,6 +73,9 @@ jobs:
- uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: ${{ env.DOCKER_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ steps.date.outputs.yesterday }}
tags: |
${{ env.DOCKER_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ steps.date.outputs.yesterday }}
${{ env.DOCKER_REPOSITORY }}/${{ env.IMAGE_NAME }}:latest
61 changes: 61 additions & 0 deletions .github/workflows/update_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: DB Backup and Schema Update

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: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up PostgreSQL client
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
- 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: |
PGPASSWORD=$PGPASSWORD pg_restore -h $PGHOST -U $PGUSER -d $PGDATABASE -c -v backup.backup
- name: Fetch database schema
run: |
PGPASSWORD=$PGPASSWORD pg_dump -h $PGHOST -U $PGUSER -d $PGDATABASE --schema-only --schema=public --schema=b > schema.sql
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: Update database schema
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

0 comments on commit ccac195

Please sign in to comment.