paritytech / substrate-archive

Blockchain Indexing Engine
GNU General Public License v3.0
196 stars 74 forks source link

Unclear how to set up the database #423

Open sacha-l opened 2 years ago

sacha-l commented 2 years ago

In the Quick start section, it says to run: source ./substrate-archive/scripts/up.sh, however the script no longer exists there. Is this still relevant? It seemed like a nice feature!

In general, it's unclear how to get the SQL database up and running:

If you can help me answer these questions I'll make a follow-up PR with the clarifications I think are needed. Thanks! 😃

fishmonger45 commented 2 years ago

Docs are pretty out of date. I suggest just using the included docker-compose to get a db up and running

xcaptain commented 2 years ago
  1. Run docker-compose up -d to start postgres and pgadmin
  2. Run DATABASE_URL=postgres://postgres:123@localhost:6432/local_chain_db sqlx database create in substrate-archive/src to create the database.
  3. Run DATABASE_URL=postgres://postgres:123@localhost:6432/local_chain_db sqlx migrate run in substrate-archive/src` to create the tables.
  4. Run cargo run --release -- -c archive.toml in bin/node-template-archive/ to start indexing. Keep in mind to modify the archive.toml configs.
insipx commented 2 years ago

Yeah the docs can be confusing here, I think

This example: https://github.com/paritytech/substrate-archive/wiki/1).-Requirements#example-setting-up-the-database seems to be the right place to provide steps on how to do this. Perhaps we could add instructions for different OS users. For me on macos when I run createuser -s postgres, I get: createuser: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?

I haven't had trouble with this on MacOS, this error generally occurs if the postgres server isn't running. how did you install postgres? (Postgres.app/homebrew/etc?)

This example: https://github.com/paritytech/substrate-archive/wiki/1.)-Requirements#compiling-without-a-database alludes to the fact that you can still run the substrate-archive CLI without a database. But it's not so clear how. Where do I set SQLX_OFFLINE=true for example?

Yeah I think this should have been more clear. SQLX_OFFLINE is not meant to enable archive to run without postgres/rocksdb but just to compile it for use in the context of something like CI. I.E SQLX_OFFLINE=true cargo check

What issue are you running into with node-template? It should just run along node-template-archive. It's easiest to bring up postgres/rabbitmq with docker-compose and then run node-template/archive combo after creating postgres user/database in docker-postgres. Thing to remember there would be to change the postgres port in archive.toml if you are running with a non-standard port in docker