Commit 5dfc6f50 authored by Will Cory's avatar Will Cory

feat(indexer): Add prisma ui

parent a1ec9142
...@@ -38,13 +38,27 @@ services: ...@@ -38,13 +38,27 @@ services:
- INDEXER_REST_HOSTNAME=0.0.0.0 - INDEXER_REST_HOSTNAME=0.0.0.0
- INDEXER_REST_PORT=8080 - INDEXER_REST_PORT=8080
- INDEXER_BEDROCK_L1_STANDARD_BRIDGE=0 - INDEXER_BEDROCK_L1_STANDARD_BRIDGE=0
- INDEXER_BEDROCK_L1_STANDARD_BRIDGE=0x636Af16bf2f682dD3109e60102b8E1A089FedAa8 - INDEXER_BEDROCK_L1_STANDARD_BRIDGE=${INDEXER_BEDROCK_L1_STANDARD_BRIDGE:-0x636Af16bf2f682dD3109e60102b8E1A089FedAa8}}
- INDEXER_BEDROCK_OPTIMISM_PORTAL=0xB7040fd32359688346A3D1395a42114cf8E3b9b2 - INDEXER_BEDROCK_OPTIMISM_PORTAL=${INDEXER_BEDROCK_OPTIMISM_PORTAL:-0xB7040fd32359688346A3D1395a42114cf8E3b9b2}
- INDEXER_L1_ADDRESS_MANAGER_ADDRESS=${INDEXER_L1_ADDRESS_MANAGER_ADDRESS:-0xdE1FCfB0851916CA5101820A69b13a4E276bd81F}
ports: ports:
- 8080:8080 - 8080:8080
depends_on: depends_on:
postgres: postgres:
condition: service_healthy condition: service_healthy
ui:
build:
context: ..
dockerfile: indexer/ui/Dockerfile
environment:
- DATABASE_URL=${DATABASE_URL:-postgresql://db_username:db_password@postgres:5432/db_name}
ports:
- 5555:5555
healthcheck:
test: wget localhost:5555 -q -O - > /dev/null 2>&1
depends_on:
postgres:
condition: service_healthy
volumes: volumes:
postgres_data: postgres_data:
...@@ -2,3 +2,5 @@ ...@@ -2,3 +2,5 @@
INDEXER_L1_ETH_RPC=FILL_ME_IN INDEXER_L1_ETH_RPC=FILL_ME_IN
INDEXER_L2_ETH_RPC=FILL_ME_IN INDEXER_L2_ETH_RPC=FILL_ME_IN
# Fill in to use prisma studio ui with a db other than the default
# DATABASE_URL=FILL_ME_IN
FROM node:18.16.0-bullseye-slim
WORKDIR /app
RUN echo {} > package.json && \
npm install prisma
COPY indexer/ui/schema.prisma schema.prisma
RUN npx prisma generate --schema schema.prisma
CMD ["npx", "prisma", "studio", "--port", "5555", "--hostname", "0.0.0.0", "--schema", "schema.prisma" ]
## @eth-optimism/indexer-ui
A simple UI for exploring the indexer DB using [Prisma studio](https://www.prisma.io)
## Usage
Included in the docker-compose file as `ui` service
```bash
docker-compose up
```
Prisma can be viewed at [localhost:5555](http://localhost:5555)
## Update the schema
The [prisma schema](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference) is what allows prisma to work. It is automatically generated from the db schema.
To update the schema to the latest db schema simply pass in the database url to [prisma pull](https://www.prisma.io/docs/reference/api-reference/command-reference#db-pull). Prisma pull will introspect the schema and generate a prisma schema
```bash
DATABASE_URL=postgresql://db_username:db_password@postgres:5432/db_name npx prisma db pull
```
## Other functionality
We mostly just use prisma as a UI. But brisma provides much other functionality that can be useful including.
- Ability to change the [db schema](https://www.prisma.io/docs/reference/api-reference/command-reference#db-push) direction from modifying the [schema.prisma](./schema.prisma) in place. This can be a fast way to [start prototyping](https://www.prisma.io/docs/guides/migrate/prototyping-schema-db-push)
- Ability to [seed the database](https://www.prisma.io/docs/guides/migrate/seed-database)
- Ability to write quick scripts with [prisma client](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference)
## Running prisma studio outside of docker
Prisma can also be run with [npx](https://docs.npmjs.com/cli/v8/commands/npx)
```bash
npx prisma studio --schema indexer/ui/schema.prisma
```
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model airdrops {
address String @id @db.VarChar(42)
voter_amount String @default("0") @db.VarChar
multisig_signer_amount String @default("0") @db.VarChar
gitcoin_amount String @default("0") @db.VarChar
active_bridged_amount String @default("0") @db.VarChar
op_user_amount String @default("0") @db.VarChar
op_repeat_user_amount String @default("0") @db.VarChar
op_og_amount String @default("0") @db.VarChar
bonus_amount String @default("0") @db.VarChar
total_amount String @db.VarChar
}
model deposits {
guid String @id @db.VarChar
from_address String @db.VarChar
to_address String @db.VarChar
l1_token String @db.VarChar
l2_token String @db.VarChar
amount String @db.VarChar
data Bytes
log_index Int
block_hash String @db.VarChar
tx_hash String @db.VarChar
l1_blocks l1_blocks @relation(fields: [block_hash], references: [hash], onDelete: NoAction, onUpdate: NoAction)
l1_tokens l1_tokens @relation(fields: [l1_token], references: [address], onDelete: NoAction, onUpdate: NoAction)
}
model l1_blocks {
hash String @id @db.VarChar
parent_hash String @db.VarChar
number Int @unique(map: "l1_blocks_number")
timestamp Int
deposits deposits[]
state_batches state_batches[]
}
model l1_tokens {
address String @id @db.VarChar
name String @db.VarChar
symbol String @db.VarChar
decimals Int
deposits deposits[]
}
model l2_blocks {
hash String @id @db.VarChar
parent_hash String @db.VarChar
number Int @unique(map: "l2_blocks_number")
timestamp Int
withdrawals withdrawals[]
}
model l2_tokens {
address String @id
name String
symbol String
decimals Int
withdrawals withdrawals[]
}
model state_batches {
index Int @id
root String @db.VarChar
size Int
prev_total Int
extra_data Bytes
block_hash String @db.VarChar
l1_blocks l1_blocks @relation(fields: [block_hash], references: [hash], onDelete: NoAction, onUpdate: NoAction)
withdrawals withdrawals[]
@@index([block_hash], map: "state_batches_block_hash")
@@index([prev_total], map: "state_batches_prev_total")
@@index([size], map: "state_batches_size")
}
model withdrawals {
guid String @id @db.VarChar
from_address String @db.VarChar
to_address String @db.VarChar
l1_token String @db.VarChar
l2_token String @db.VarChar
amount String @db.VarChar
data Bytes
log_index Int
block_hash String @db.VarChar
tx_hash String @db.VarChar
state_batch Int?
br_withdrawal_hash String? @db.VarChar
br_withdrawal_proven_tx_hash String? @db.VarChar
br_withdrawal_proven_log_index Int?
br_withdrawal_finalized_tx_hash String? @db.VarChar
br_withdrawal_finalized_log_index Int?
br_withdrawal_finalized_success Boolean?
l2_blocks l2_blocks @relation(map: "l2", fields: [block_hash], references: [hash], onDelete: NoAction, onUpdate: NoAction)
l2_tokens l2_tokens @relation(fields: [l2_token], references: [address], onDelete: NoAction, onUpdate: NoAction)
state_batches state_batches? @relation(fields: [state_batch], references: [index], onDelete: NoAction, onUpdate: NoAction)
@@index([br_withdrawal_hash], map: "withdrawals_br_withdrawal_hash")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment