Skip to content

Commit

Permalink
Supabase dumper & restorer
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Nov 21, 2023
1 parent e26cff0 commit f761759
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ dist-ssr
*.sw?
ngrok
.dev.vars

dumper/dump.sql
7 changes: 7 additions & 0 deletions dumper/confirm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
confirm() {
read -r -p "${1:-Are you sure? [y/N]} " response
if [ "$response" != "y" ]; then
echo "Operation cancelled."
exit 1
fi
}
6 changes: 6 additions & 0 deletions dumper/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.8'
services:
postgres:
image: postgres:15.1
environment:
POSTGRES_PASSWORD: example
13 changes: 13 additions & 0 deletions dumper/dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(dirname "$0")"

source "$SCRIPT_DIR/confirm.sh"

confirm "Are you sure you want to create a prod dump? [y/N]"

export $(cat "$SCRIPT_DIR/../.dev.vars" | xargs)

docker-compose exec postgres pg_dump postgresql://postgres:$DB_PASS@$DB_HOST:5432/$DB_NAME > "$SCRIPT_DIR/dump.sql"
19 changes: 19 additions & 0 deletions dumper/restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(dirname "$0")"

source "$SCRIPT_DIR/confirm.sh"

if [ ! -f "$SCRIPT_DIR/dump.sql" ]; then
echo "Error: dump.sql does not exist."
exit 1
fi

export $(cat "$SCRIPT_DIR/../.dev.vars" | xargs)

confirm "Are you sure you want to execute the psql command? [y/N]"

docker-compose exec postgres psql postgresql://postgres:$DB_PASS@$DB_HOST:5432/$DB_NAME < "$SCRIPT_DIR/dump.sql"

0 comments on commit f761759

Please sign in to comment.