Skip to content

Commit

Permalink
Migrate db after each restart (#2245)
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed May 16, 2022
1 parent b37da6f commit cfd225e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docker/data-restore/data-restore-entry.sh
Expand Up @@ -2,16 +2,21 @@

set -e

function migrate() {
function reset_db() {
cd core/lib/storage
psql "$DATABASE_URL" -c 'DROP OWNED BY CURRENT_USER CASCADE' || /bin/true
psql "$DATABASE_URL" -c 'DROP SCHEMA IF EXISTS public CASCADE' || /bin/true
psql "$DATABASE_URL" -c 'CREATE SCHEMA public'
diesel database setup
cd $ZKSYNC_HOME
}

function migrate() {
cd core/lib/storage
diesel database setup
diesel migration run
cd $ZKSYNC_HOME
}

cd $ZKSYNC_HOME

# Wait for the database to be ready.
Expand All @@ -28,7 +33,7 @@ fi
case $COMMAND in
genesis)
echo "Resetting the database"
migrate
reset_db
COMMAND="--genesis"
;;
continue)
Expand Down Expand Up @@ -68,7 +73,7 @@ then
# Do not drop db if the file doesn't exist.
[ -f $PG_DUMP_PATH/$PG_DUMP ] || { echo "$PG_DUMP_PATH/$PG_DUMP not found" ; exit 1 ; }

migrate
reset_db

echo "Applying $PG_DUMP"
pg_restore -j 8 -d $DATABASE_URL --clean --if-exists $PG_DUMP_PATH/$PG_DUMP
Expand All @@ -81,4 +86,5 @@ else
CONFIG_FILE="${CONFIG_PATH}/${NETWORK}.json"
fi

migrate
$ZKSYNC_HOME/target/release/zksync_data_restore $COMMAND $MODE --config $CONFIG_FILE --web3 $WEB3_URL || exit 1

0 comments on commit cfd225e

Please sign in to comment.