-
-
Notifications
You must be signed in to change notification settings - Fork 6
44 lines (39 loc) · 1.35 KB
/
sync.yml
File metadata and controls
44 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: Sync to Staging
on:
workflow_dispatch:
schedule:
- cron: '0 0 */5 * *'
jobs:
sync:
name: Sync Production → Staging
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'SwiftLeeds' }}
steps:
- name: Install PostgreSQL 17 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-17
- name: Dump production database (public schema only)
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: |
/usr/lib/postgresql/17/bin/pg_dump "$DATABASE_URL" \
--schema=public \
--no-owner \
--no-privileges \
--format=custom \
--file=prod_dump.dump
- name: Restore to staging database (public schema only)
env:
STAGING_DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }}
run: |
/usr/lib/postgresql/17/bin/pg_restore \
--clean \
--if-exists \
--no-owner \
--no-privileges \
--schema=public \
--dbname="$STAGING_DATABASE_URL" \
prod_dump.dump