Skip to content

Commit

Permalink
feat: Expand Demo to sync data to target DB with axon
Browse files Browse the repository at this point in the history
  • Loading branch information
13rac1 committed Apr 16, 2020
1 parent f06083a commit dc71281
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ go get github.com/perangel/warp-pipe/...

## Demo

A demo is available of Changesets. A backend application connects to the Warp
Pipe Changesets table list, then broadcasts to a front-end application via
websockets.
The demo shows how data in a Source DB can be accessed as a stream and used to
sync to a Target DB.

1. Creates two databases in Docker.
2. Sets up a schema on the Source DB.
3. Sets up a schema on the Target DB.
4. Runs `warp-pipe setup-db` on the Source DB.
5. Pauses to allow the user to load a front-end web application which loads Warp
Pipe Changesets via websockets.
6. Adds data to the Source DB.
7. Runs `axon` to sync data from the Source to Target.

Run:

Expand Down
32 changes: 31 additions & 1 deletion scripts/setup_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ DB_NAME=${DB_NAME:-demo}
docker-compose -f $basename/../docker-compose.demo.yml up -d

until nc -w 1 -z $DB_HOST $DB_PORT; do
echo "Waiting for db... sleeping"
echo "Waiting for source db... sleeping"
sleep 2
done
until nc -w 1 -z $DB_HOST 6432; do
echo "Waiting for target db... sleeping"
sleep 2
done

echo "db available"
sleep 2

echo "Setup Schema on Source"
docker-compose -f $basename/../docker-compose.demo.yml \
exec -T -e PGPASSWORD=$DB_PASS source_db \
psql \
-h $DB_HOST \
-p $DB_PORT \
-U $DB_USER \
-d $DB_NAME \
-c "$(cat $sqldir/create_fixture_schema.sql)"

echo "Setup Schema on Target"
docker-compose -f $basename/../docker-compose.demo.yml \
exec -T -e PGPASSWORD=$DB_PASS target_db \
psql \
-h $DB_HOST \
-U $DB_USER \
-d $DB_NAME \
-c "$(cat $sqldir/create_fixture_schema.sql)"
Expand All @@ -34,10 +50,24 @@ warp-pipe setup-db -H $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -P $DB_PASS
echo "Load the websocket demo app: http://localhost:8080/"
read -p "Then press <Enter> to import SQL fixtures to see Warp Pipe Changesets get created..."

echo "Add data to Source"
docker-compose -f $basename/../docker-compose.demo.yml \
exec -T -e PGPASSWORD=$DB_PASS source_db \
psql \
-h $DB_HOST \
-U $DB_USER \
-d $DB_NAME \
-c "$(cat $sqldir/create_fixture_data.sql)"

echo "Run axon to sync all changes. CTRL-C to exit when done."
AXON_TARGET_DB_PORT=6432
AXON_SOURCE_DB_PASS=demo
AXON_TARGET_DB_NAME=demo
AXON_SOURCE_DB_NAME=demo
AXON_SOURCE_DB_PORT=5432
AXON_TARGET_DB_USER=demo
AXON_SOURCE_DB_USER=demo
AXON_TARGET_DB_PASS=demo
AXON_SOURCE_DB_HOST=localhost
AXON_TARGET_DB_HOST=localhost
go run cmd/axon/*.go

0 comments on commit dc71281

Please sign in to comment.