From 1cbd70e57c4fc7b2464d02c40cc26a3881f5bf72 Mon Sep 17 00:00:00 2001 From: Ashwin Phatak Date: Thu, 12 Aug 2021 14:54:31 +0530 Subject: [PATCH] Add script to reset the databases. (#211) Co-authored-by: prathamesh0 --- README.md | 8 ++++++++ package.json | 3 ++- scripts/reset-dbs.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 scripts/reset-dbs.sh diff --git a/README.md b/README.md index a90c335c..c93b4838 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,14 @@ CREATE EXTENSION uni-watcher-job-queue=# exit ``` +#### Reset + +Reset the databases used by the watchers: + +```bash +yarn db:reset +``` + ## Run To run any watcher, `cd` into their package folder and run: diff --git a/package.json b/package.json index 9081362d..52a7a2da 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "test": "lerna run test --stream --no-bail", "lint": "lerna run lint --stream", - "build:contracts": "lerna run build:contracts" + "build:contracts": "lerna run build:contracts", + "db:reset": "sudo ./scripts/reset-dbs.sh" } } diff --git a/scripts/reset-dbs.sh b/scripts/reset-dbs.sh new file mode 100755 index 00000000..518cf175 --- /dev/null +++ b/scripts/reset-dbs.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +echo WARNING: This will reset all the databases used by the watchers. +read -p "Do you want to continue? (y/n)" choice +if [[ $choice =~ ^(Y|y| ) ]] +then + sudo -i -u postgres bash << EOF + export PGPASSWORD=postgres + + dropdb erc20-watcher + dropdb address-watcher + dropdb uni-watcher + dropdb uni-info-watcher + + createdb erc20-watcher + createdb address-watcher + createdb uni-watcher + createdb uni-info-watcher + + psql -d address-watcher-job-queue -c "delete from pgboss.job;" + psql -d uni-watcher-job-queue -c "delete from pgboss.job;" + psql -d uni-info-watcher-job-queue -c "delete from pgboss.job;" +EOF +else + echo "Abort." +fi