diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b1fa07a..9facd41 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,24 +22,36 @@ jobs: passphrase: ${{ secrets.SSH_PASSPHRASE }} port: 22 script: | - # Ensure Rust installed via rustup is used export PATH="$HOME/.cargo/bin:$PATH" - - # Verify Cargo is available cargo --version || { echo "Cargo not found"; exit 1; } - # Navigate to the project directory cd fossil-headers-db git fetch origin main git reset --hard origin/main - - # Build the project cargo build --release - - # Move the binary to the correct location sudo mv target/release/fossil_headers_db /usr/local/bin/fossil_headers_db - # Restart the service sudo systemctl daemon-reload sudo systemctl restart fossil_headers_db sudo systemctl status fossil_headers_db --no-pager + + # Fetch the first missing block - 1 using PSQL + START_BLOCK=$(psql -U postgres -d fossil -t -c " + WITH block_range AS ( + SELECT MIN(number) AS min_block, MAX(number) AS max_block + FROM public.blockheaders + ), all_blocks AS ( + SELECT n AS block_number + FROM generate_series( + (SELECT min_block FROM block_range), + (SELECT max_block FROM block_range) + ) n + ), missing_blocks AS ( + SELECT all_blocks.block_number + FROM all_blocks + LEFT JOIN public.blockheaders bh ON all_blocks.block_number = bh.number + WHERE bh.number IS NULL + ) SELECT MIN(block_number) - 1 FROM missing_blocks;") + + # Run cargo with the calculated start block + nohup cargo run fix --start $START_BLOCK &