Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexer PostgreSQL install instructions #774

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Each core processor indexes a specific type of data.
You can explore the [full list of processors](https://github.com/aptos-labs/aptos-indexer-processors/tree/main/rust/sdk-processor/src/processors) and the [complete indexer data schema](https://github.com/aptos-labs/aptos-indexer-processors/blob/main/rust/processor/src/db/postgres/schema.rs).

The Aptos core processors and the [Quickstart Guide](../quickstart.mdx) use [PostgreSQL](https://www.postgresql.org/) as the database and [Diesel](https://diesel.rs/) as the ORM.
However, you are free to choose any database or ORM that fits your needs.
If you'd also like to use PostgreSQL and Diesel, you can follow the instructions in [PostgreSQL Installation](../quickstart.mdx#postgresql-installation).

You're free to use whatever database and ORM you prefer.
Popular alternatives include [SeaORM](https://www.sea-ql.org/SeaORM/) and [SQLx](https://github.com/launchbadge/sqlx).
Setting up a database and using an ORM is beyond the scope of these tutorials.
If you need guidance, refer to the tutorials linked above for more information.
25 changes: 16 additions & 9 deletions apps/nextra/pages/en/build/indexer/indexer-sdk/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ You also need the following tools:

- Rust 1.79: [Installation Guide](https://www.rust-lang.org/tools/install)
- Cargo: [Installation Guide](https://doc.rust-lang.org/cargo/getting-started/installation.html#install-rust-and-cargo)
- Diesel CLI: [Installation Guide](https://diesel.rs/guides/getting-started.html)

We use PostgreSQL as our database in this tutorial. You’re free to use whatever you want, but this tutorial is geared
We use [PostgreSQL](https://www.postgresql.org/) as our database and [Diesel](https://diesel.rs/guides/getting-started) as our ORM in this tutorial. You’re free to use whatever you want, but this tutorial is geared
towards PostgreSQL for the sake of simplicity. We use the following database configuration and tools:

[PostgreSQL](https://www.postgresql.org/download/)
### PostgreSQL Installation (for macOS)
1. `brew install libpq` ([this is a postgres C API library](https://formulae.brew.sh/formula/libpq)). Also perform all export commands post-installation
rtso marked this conversation as resolved.
Show resolved Hide resolved
rtso marked this conversation as resolved.
Show resolved Hide resolved
```bash
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
```
2. `brew install postgres`
3. `pg_ctl -D /opt/homebrew/var/postgres start` or `brew services start postgresql`
4. `/opt/homebrew/bin/createuser -s postgres`
5. Ensure you're able to do: `psql postgres`
6. `cargo install diesel_cli --no-default-features --features postgres`
7. Make sure that you're in the DB folder (run `cd src/db/postgres` from base directory), run `diesel migration run --database-url postgresql://localhost/postgres`
a. If for some reason this database is already being used, try a different db. e.g.
`DATABASE_URL=postgres://postgres@localhost:5432/indexer_v2 diesel database reset`

- We will use a database hosted on `localhost` on the port `5432`, which should be the default.
- When you create your username, keep track of it and the password you use for it.
- You can view a tutorial for installing PostgreSQL and
psql [here](https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-22-04-quickstart)
tool to set up your database more quickly.
- To easily view your database data, consider using a GUI like [DBeaver](https://dbeaver.io/)
*recommended*, [pgAdmin](https://www.pgadmin.org/), or [Postico](https://eggerapps.at/postico2/).

Explaining how to create a database is beyond the scope of this tutorial. If you are not sure how to do it, consider
checking out tutorials on how to create a database with the `psql` tool.

## Setting up your environment

Make sure to start the `postgresql` service:
Expand Down
Loading