Commit f7b73857 authored by Will Cory's avatar Will Cory

feat(indexer): Add script to update prisma ui

Update indexer/ui/schema.prisma

give up on ci
parent 072c254d
......@@ -60,5 +60,20 @@ services:
depends_on:
postgres:
condition: service_healthy
prisma-check:
restart: "no"
build:
context: ..
dockerfile: indexer/ui/Dockerfile
command: ./prisma.sh --check
environment:
- DATABASE_URL=${DATABASE_URL:-postgresql://db_username:db_password@postgres:5432/db_name}
depends_on:
indexer:
condition: service_healthy
postgres:
condition: service_healthy
volumes:
postgres_data:
......@@ -5,6 +5,7 @@ WORKDIR /app
RUN echo {} > package.json && \
npm install prisma
COPY indexer/ui/prisma.sh prisma.sh
COPY indexer/ui/schema.prisma schema.prisma
RUN npx prisma generate --schema schema.prisma
......
......@@ -16,10 +16,10 @@ Prisma can be viewed at [localhost:5555](http://localhost:5555)
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
To update the schema to the latest db schema start the database and run [./ui/prisma.sh](./prisma.sh). Optionally pass in a DATABASE_URL if not the default
```bash
DATABASE_URL=postgresql://db_username:db_password@postgres:5432/db_name npx prisma db pull
DATABASE_URL=postgresql://db_username:db_password@postgres:5432/db_name
```
## Other functionality
......
#!/usr/bin/env bash
# This script updates the prisma schema
#
SCRIPT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
DATABASE_URL=${DATABASE_URL:-postgresql://db_username:db_password@localhost:5434/db_name}
PRISMA_FILE="$SCRIPT_DIR/schema.prisma"
TEMP_FILE="$SCRIPT_DIR/temp-schema.prisma"
function update_prisma() {
echo "Updating Prisma Schema..."
npx prisma db pull --url $DATABASE_URL --schema $PRISMA_FILE
echo "Update completed."
}
function check_prisma() {
echo "Checking Prisma Schema..."
cp $PRISMA_FILE $TEMP_FILE
npx prisma db pull --url $DATABASE_URL --schema $TEMP_FILE
diff $PRISMA_FILE $TEMP_FILE > /dev/null
if [ $? -eq 0 ]; then
echo "Prisma Schema is up-to-date."
rm $TEMP_FILE
else
echo "Prisma Schema is not up-to-date."
rm $TEMP_FILE
return 1
fi
}
if [ "$1" == "--check" ]; then
check_prisma
else
update_prisma
fi
......@@ -101,7 +101,7 @@ model withdrawals {
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_blocks l2_blocks @relation(fields: [block_hash], references: [hash], onDelete: NoAction, onUpdate: NoAction, map: "l2")
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)
......
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