From 970f08d884e0f92d8e928497f15b83d21f03f09a Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Sun, 12 May 2024 23:51:23 +0100 Subject: [PATCH] [Indexer/TiDB][EASY] Add pre-requisites to README. ## Description Explain what needs to be installed to get the MySQL version of the Indexer working. ## Test plan Try the steps and make sure they work. --- crates/sui-indexer/README.md | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/sui-indexer/README.md b/crates/sui-indexer/README.md index a04edab9215a1..e136b7c4d5927 100644 --- a/crates/sui-indexer/README.md +++ b/crates/sui-indexer/README.md @@ -59,26 +59,56 @@ Run this command under `sui/crates/sui-indexer`, which will wipe DB; In case of ```sh diesel database reset --database-url="" ``` -### Local Development(TiDB) + +## Steps to run locally (TiDB) + +### Prerequisites + +1. Install TiDB + +``` sh +curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh +``` + +2. Install a compatible version of MySQL (At the time of writing, this is MySQL 8.0 -- note that 8.3 is incompatible). + +``` sh +brew install mysql@8.0 +``` + +3. Install a version of `diesel_cli` that supports MySQL (and probably also Postgres). This version of the CLI needs to be built against the version of MySQL that was installed in the previous step (compatible with the local installation of TiDB, 8.0.37 at time of writing). + +``` sh +MYSQLCLIENT_LIB_DIR=/opt/homebrew/Cellar/mysql@8.0/8.0.37/lib/ cargo install diesel_cli --no-default-features --features postgres --features mysql --force +``` + +### Run the indexer + 1.Run TiDB + ```sh -curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh tiup playground ``` + 2.Verify tidb is running by connecting to it using the mysql client, create database `test` + ```sh mysql --comments --host 127.0.0.1 --port 4000 -u root create database test; -``` +``` + 3.DB setup, under `sui/crates/sui-indexer` run: + ```sh # an example DATABASE_URL is "mysql://root:password@127.0.0.1:4000/test" diesel setup --database-url=" --migration-dir='migrations/mysql'" diesel database reset --database-url=" --migration-dir='migrations/mysql'" ``` + Note that you'll need an existing database for the above to work. Replace `test` with the name of the database created. 4. run indexer as a writer, which pulls data from fullnode and writes data to DB + ```sh # Change the RPC_CLIENT_URL to http://0.0.0.0:9000 to run indexer against local validator & fullnode cargo run --bin sui-indexer --features mysql-feature --no-default-features -- --db-url "" --rpc-client-url "https://fullnode.devnet.sui.io:443" --fullnode-sync-worker --reset-db -``` \ No newline at end of file +```