Skip to content

Commit

Permalink
Avoid zk in data restore (#2238)
Browse files Browse the repository at this point in the history
* Avoid zk in data restore

Signed-off-by: deniallugo <[email protected]>

* Make migrate function for data-restore

Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo authored May 4, 2022
1 parent 991f0e1 commit 1468bf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 1 addition & 4 deletions docker/data-restore/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.53
FROM rust:1.60

WORKDIR /usr/src/zksync

Expand Down Expand Up @@ -30,8 +30,5 @@ COPY docker/data-restore/data-restore-entry.sh /bin/
# Setup the environment
ENV ZKSYNC_HOME=/usr/src/zksync
ENV PATH="${ZKSYNC_HOME}/bin:${PATH}"
ENV IN_DOCKER=true

RUN cd $ZKSYNC_HOME && zk

ENTRYPOINT ["data-restore-entry.sh"]
23 changes: 15 additions & 8 deletions docker/data-restore/data-restore-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

set -e

cd $ZKSYNC_HOME
function migrate() {
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'

cd core/lib/storage
diesel database setup
diesel migration run
cd $ZKSYNC_HOME
}

# Load the environment
export $(cat $ZKSYNC_HOME/etc/env/docker.env | sed 's/#.*//g' | xargs)
cd $ZKSYNC_HOME

# Wait for the database to be ready.
until pg_isready -d $DATABASE_URL; do
Expand All @@ -21,8 +29,7 @@ fi
case $COMMAND in
genesis)
echo "Resetting the database"
zk db drop || true
zk db basic-setup
migrate
COMMAND="--genesis"
;;
continue)
Expand Down Expand Up @@ -62,12 +69,12 @@ then
# Do not drop db if the file doesn't exist.
[ -f /pg_restore/$PG_DUMP ] || { echo "$PG_DUMP not found" ; exit 1 ; }

zk db drop || true
zk db basic-setup
migrate

echo "Applying $PG_DUMP"
pg_restore -j 8 -d $DATABASE_URL --clean --if-exists /pg_restore/$PG_DUMP
fi

CONFIG_FILE="/usr/src/configs/${NETWORK}.json"

zk f ./target/release/zksync_data_restore $COMMAND $MODE --config $CONFIG_FILE --web3 $WEB3_URL || exit 1
./target/release/zksync_data_restore $COMMAND $MODE --config $CONFIG_FILE --web3 $WEB3_URL || exit 1

0 comments on commit 1468bf6

Please sign in to comment.