near / near-indexer-for-explorer

Watch NEAR network and store all the data from NEAR blockchain to PostgreSQL database
https://near-indexers.io/docs/projects/near-indexer-for-explorer
GNU General Public License v3.0
123 stars 56 forks source link

Diesel migration run fails with "error applying hunk #1" #299

Open sotcsa opened 1 year ago

sotcsa commented 1 year ago

I have tried to build the indexer - following the steps:

git clone git@github.com:near/near-indexer-for-explorer.git cd near-indexer-for-explorer echo "DATABASE_URL=postgres://xxx:yyy@zzzz/dbdbdbd" > .env cargo install diesel_cli --no-default-features --features "postgres" diesel migration run

With the latest master commit, diesel migration run fails:

Running migration 2021-10-04-100000_assets_nft Running migration 2021-10-14-180948_add_resharding_state_change_reason_kind Running migration 2022-01-12-100000_assets_ft Running migration 2022-01-26-184200_drop_duplicated_index_execution_outcome Running migration 2022-01-26-184201_index_action_receipt_actions Running migration 2022-06-07-000000_drop_action_receipt_actions_args_amount_index Running migration 2022-08-12-123800_ft_nft_indexes error applying hunk #1

Versions:

OS: Ubuntu 20.04.5 LTS diesel 2.0.0 rustc 1.63.0 (4b91a6ea7 2022-08-08)

pkudinov commented 1 year ago

Hi, @sotcsa thanks for raising this. Were you able to work around the issue? If you did, please feel free to submit a request. Meanwhile, we will put this on our backlog.

khorolets commented 1 year ago

@sotcsa hey there! Could you tell me what version of PostgreSQL do you use?

FYI, I've tried to apply the migrations on the newly created database locally and couldn't reproduce the bug.

I am using PostgreSQL 14.4

diesel migration run                                                                                                                                                07:50:02
Running migration 2020-12-07-153402_initial_schema
Running migration 2021-01-14-170424_index-receipt-originated-from-transaction-hash
Running migration 2021-01-20-152056_index-transactions-receiver-account-id
Running migration 2021-03-11-123839_index-action-kind-and-status
Running migration 2021-04-22-090505_execution_outcomes_replace_chunk_relation_with_shard_id
Running migration 2021-04-28-154439_denormalize_action_receipt_actions
Running migration 2021-05-06-093622_additional_indexes_for_action_receipt_actions
Running migration 2021-05-07-115559_convert_args_base64_to_args_json
Running migration 2021-05-10-084700_indexer_on_args_field
Running migration 2021-05-27-154211_account_changes_unique_idx
Running migration 2021-06-02-173100_add_migration_state_change_reason_kind
Running migration 2021-08-02-183200_transactions_sorting_idx
Running migration 2021-08-04-151515_circulating_supply_table
Running migration 2021-08-06-123500_account_changes_ordering_column
Running migration 2021-08-11-163800_account_changes_ordering_idx
Running migration 2021-10-04-100000_assets_nft
Running migration 2021-10-14-180948_add_resharding_state_change_reason_kind
Running migration 2022-01-12-100000_assets_ft
Running migration 2022-01-26-184200_drop_duplicated_index_execution_outcome
Running migration 2022-01-26-184201_index_action_receipt_actions
Running migration 2022-06-07-000000_drop_action_receipt_actions_args_amount_index
Running migration 2022-08-12-123800_ft_nft_indexes
sotcsa commented 1 year ago

Hi @khorolets

PostgreSQL 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit

khorolets commented 1 year ago

I can't identify a problem as I cannot reproduce it. Could you try to apply that failing migration manually by just copying the SQL query from the up.sql file directly to your database and see if there is any useful error

cc @telezhnaya

frol commented 1 year ago

@sotcsa The error "error applying hunk #1" does not look like one Postgres could return. It sounds like patch error which I don't see a reason to get here. Please, check that you don't have any merge conflicts in the repo and provide the screenshots of the commands you run with their outputs as well as the git status output.

diepvuongthang commented 1 year ago

I am also facing the same problem.

telezhnaya commented 1 year ago

Migration looks good. Please copy-paste the SQL, run it manually, and provide the error here.

CodeDem commented 1 year ago

I got the same error on the lastest migration 2022-08-12-123800_ft_nft_indexes -> error applying hunk #1 . I tried to run that manually on Postgres by copy-pasting from up.sql and it worked.

sotcsa commented 1 year ago

Maybe the problem comes from the different ways of testing. We are using an empty database, with fresh checkout, and fresh diesel install. @telezhnaya could you please provide a detailed process of how we should install first time?

On my first message I added hoow I did it from scratch - and can't see anytime working:

git clone git@github.com:near/near-indexer-for-explorer.git
cd near-indexer-for-explorer
echo "DATABASE_URL=postgres://xxx:yyy@zzzz/dbdbdbd" > .env
cargo install diesel_cli --no-default-features --features "postgres"
diesel migration run
Madgeniusblink commented 1 year ago

@sotcsa were you able to run the manual SQL command and post that cargo build --release?

I think issue #302 is also linked to this

rayn316 commented 1 year ago

I have the same problem Hello, I'm having trouble starting after upgrading near-indexer-for-explorer to version 0.10.23 The execution of sql is normal, but the execution of cargo build --release failed

OS: ubuntu 20.04 postgresql: 14 err.txt

frol commented 1 year ago

@sundafa The issue you report seems to be completely different one. Try fresh checkout from master as our CI passes just fine.

sotcsa commented 1 year ago

@sotcsa were you able to run the manual SQL command and post that cargo build --release?

I think issue #302 is also linked to this

That issue is the very same, if I don't stop at the first error, got the same result with the cargo build.

Team, could you describe please how you tested it whether it's working or not? Do you use a fresh DB and clean checkout? Many thanks.

CodeDem commented 1 year ago

@frol

I tried to pull a fresh copy of the master branch and used docker postgres:latest. I confirm the same issue. Tested on two platforms

Ubuntu 22 and Mac OS M1

Step followed

 git clone git@github.com:near/near-indexer-for-explorer.git
cd near-indexer-for-explorer
echo "DATABASE_URL=postgres://xxx:yyy@zzzz/db-name" > .env
cargo install diesel_cli --no-default-features --features "postgres"
diesel migration run
CodeDem commented 1 year ago

Just an update, I saw that when I try to run diesel migration run it fails with an error error applying hunk #1 and makes the src/schema.rs file blank. @sotcsa this is the reason for your cargo build to fail.

A temporary workaround

bimmerv commented 1 year ago

Hi. I have the same problem. When i try to run diesel migration run

I receive

Running migration 2021-08-02-183200_transactions_sorting_idx

Running migration 2021-08-04-151515_circulating_supply_table

Running migration 2021-08-06-123500_account_changes_ordering_column

Running migration 2021-08-11-163800_account_changes_ordering_idx

Running migration 2021-10-04-100000_assets_nft

Running migration 2021-10-14-180948_add_resharding_state_change_reason_kind

Running migration 2022-01-12-100000_assets_ft

Running migration 2022-01-26-184200_drop_duplicated_index_execution_outcome

Running migration 2022-01-26-184201_index_action_receipt_actions

Running migration 2022-06-07-000000_drop_action_receipt_actions_args_amount_index

Running migration 2022-08-12-123800_ft_nft_indexes

error applying hunk #1

If I try to run commands, stored in migrations/2022-08-12-123800_ft_nft_indexes/up.sql

Then I receiving these errors:

postgres=> CREATE INDEX assets__ft_contract_id_idx ON assets__fungible_token_events (emitted_by_contract_account_id);
ERROR:  relation "assets__fungible_token_events" does not exist
postgres=> CREATE INDEX assets__nft_contract_id_idx ON assets__non_fungible_token_events (emitted_by_contract_account_id);
ERROR:  relation "assets__non_fungible_token_events" does not exist
frol commented 1 year ago

Does anyone from the community have time to look into why diesel CLI leads us into this problem state? It seems to be not reproducible on our end 🤔

emarai commented 1 year ago

Encountered this error today, seemed like diesel issue [1]. Installing version 1.2 of diesel fixed this issue for me.

[1] https://github.com/rust-lang/crates.io/discussions/5348

PierreLeGuen commented 1 year ago

Facing the same issue on diesel-cli 2.0.1 and Postgres 15.

~/near-indexer-for-explorer$ cd database && diesel migration run
Running migration 2020-12-07-153402_initial_schema
Running migration 2021-01-14-170424_index-receipt-originated-from-transaction-hash
Running migration 2021-01-20-152056_index-transactions-receiver-account-id
Running migration 2021-03-11-123839_index-action-kind-and-status
Running migration 2021-04-22-090505_execution_outcomes_replace_chunk_relation_with_shard_id
Running migration 2021-04-28-154439_denormalize_action_receipt_actions
Running migration 2021-05-06-093622_additional_indexes_for_action_receipt_actions
Running migration 2021-05-07-115559_convert_args_base64_to_args_json
Running migration 2021-05-10-084700_indexer_on_args_field
Running migration 2021-05-27-154211_account_changes_unique_idx
Running migration 2021-06-02-173100_add_migration_state_change_reason_kind
Running migration 2021-08-02-183200_transactions_sorting_idx
Running migration 2021-08-04-151515_circulating_supply_table
Running migration 2021-08-06-123500_account_changes_ordering_column
Running migration 2021-08-11-163800_account_changes_ordering_idx
Running migration 2021-10-04-100000_assets_nft
Running migration 2021-10-14-180948_add_resharding_state_change_reason_kind
Running migration 2022-01-12-100000_assets_ft
Running migration 2022-01-26-184200_drop_duplicated_index_execution_outcome
Running migration 2022-01-26-184201_index_action_receipt_actions
Running migration 2022-06-07-000000_drop_action_receipt_actions_args_amount_index
Running migration 2022-08-12-123800_ft_nft_indexes
Running migration 2022-09-23-100000_index_action_receipt_actions_on_timestamp_and_order_index
Running migration 2023-02-02-100000_fungible_token_events_pk_changed
Running migration 2023-02-02-110000_non_fungible_token_events_pk_changed
Running migration 2023-02-28-160000_meta_tx
error applying hunk #1