Skip to content

Commit 2c1adef

Browse files
committed
Add a script to copy the prod db over the staging db.
1 parent f055745 commit 2c1adef

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

db/copy_prod_over_staging.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /bin/bash
2+
3+
# Use `fly proxy 5432 &` to let the below commands connect to the database.
4+
5+
# We expect .env to set $COOKBOOK_PROD_WEBSERVER_PASSWORD and $COOKBOOK_STAGING_ADMIN_PASSWORD.
6+
. .env
7+
8+
PROD_DATABASE_URL="postgres://cookbook_prod_webserver:${COOKBOOK_PROD_WEBSERVER_PASSWORD}@localhost:5432/cookbook_prod?sslmode=disable"
9+
STAGING_DATABASE_URL="postgres://cookbook_staging_admin:${COOKBOOK_STAGING_ADMIN_PASSWORD}@localhost:5432/cookbook_staging?sslmode=disable"
10+
11+
pg_dump --clean --if-exists -O -d "$PROD_DATABASE_URL" | \
12+
sed 's/cookbook_prod/cookbook_staging/g' | \
13+
pg_restore -d "$STAGING_DATABASE_URL" --single-transaction

0 commit comments

Comments
 (0)