-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-dump.sh
executable file
·49 lines (39 loc) · 1.45 KB
/
update-dump.sh
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
45
46
47
48
49
#!/bin/bash
PG_HOST_PORT=${1:-"6432"}
echo "Spinning up Postgres Docker container..."
# Start the container in the background
CONTAINER_ID=$(docker container run -d \
--cap-add SYS_RESOURCE \
--platform linux/amd64 \
-p $PG_HOST_PORT:5432 \
-e ALLOW_NOSSL=true \
-e POSTGRES_DB=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=zalando \
registry.opensource.zalan.do/acid/spilo-14:2.1-p6)
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to start container"
exit $retVal
fi
# Crude wait for container to be ready
export PROD_POSTGRES_URL=postgres://postgres:[email protected]:$PG_HOST_PORT/postgres
echo "Waiting for container to be ready..."
until psql --no-psqlrc $PROD_POSTGRES_URL -c 'select 1' 2>/dev/null 1>/dev/null; do
sleep 0.2
done
echo -e "Container is ready. Running migrations...\n"
psql --no-psqlrc $PROD_POSTGRES_URL -c "create database switchboard;";
export PROD_POSTGRES_URL=postgres://postgres:[email protected]:$PG_HOST_PORT/switchboard
# Run the migrations against the temporary Docker container
NODE_ENV=production yarn migrate:worker && NODE_ENV=production yarn migrate up
# Dump the schema using the pegged pg_dump version in the container
docker exec -e PGPASSWORD=zalando $CONTAINER_ID pg_dump -U postgres -d switchboard --schema-only \
--schema public \
--schema billing \
--schema lookup \
--schema geo \
--schema sms \
--schema worker \
> ./schema-dump.sql
docker kill $CONTAINER_ID 1>/dev/null