Skip to content

Commit

Permalink
feat: add prisma client and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
remarcable committed Apr 11, 2024
1 parent f18bf96 commit 455f60b
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COMMON_RATE_LIMIT_MAX_REQUESTS="20" # Max number of requests per window per IP

POSTGRES_USER="blobfusion"
POSTGRES_PASSWORD="blobfusion" # set own value
POSTGRES_HOST="localhost"
POSTGRES_PORT=5433
POSTGRES_DB="blobfusion"
POSTGRES_PORT=5432
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public"
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
restart: always
container_name: postgres-container
ports:
- "5433:${POSTGRES_PORT}"
- "${POSTGRES_PORT}:5432"
env_file:
- .env
environment:
Expand Down
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@asteasolutions/zod-to-openapi": "^7.0.0",
"@prisma/client": "^5.12.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"envalid": "^8.0.0",
Expand Down Expand Up @@ -51,6 +52,7 @@
"lint-staged": "^15.2.2",
"pino-pretty": "^11.0.0",
"prettier": "^3.2.5",
"prisma": "^5.12.1",
"release-it": "^17.1.1",
"rimraf": "^5.0.5",
"supertest": "^6.3.4",
Expand Down
36 changes: 36 additions & 0 deletions prisma/migrations/20240411134800_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- CreateTable
CREATE TABLE "User" (
"address" TEXT NOT NULL,
"deposits" INTEGER NOT NULL DEFAULT 0,

CONSTRAINT "User_pkey" PRIMARY KEY ("address")
);

-- CreateTable
CREATE TABLE "PartialBlob" (
"id" SERIAL NOT NULL,
"bid" INTEGER NOT NULL,
"signature" TEXT NOT NULL,
"data" BYTEA NOT NULL,
"fromAddress" TEXT NOT NULL,
"fusedBlobId" INTEGER,
"fusedBlobPosition" INTEGER,
"cost" INTEGER,

CONSTRAINT "PartialBlob_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FusedBlob" (
"id" SERIAL NOT NULL,
"txHash" TEXT,
"totalCost" INTEGER,

CONSTRAINT "FusedBlob_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "PartialBlob" ADD CONSTRAINT "PartialBlob_fromAddress_fkey" FOREIGN KEY ("fromAddress") REFERENCES "User"("address") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PartialBlob" ADD CONSTRAINT "PartialBlob_fusedBlobId_fkey" FOREIGN KEY ("fusedBlobId") REFERENCES "FusedBlob"("id") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
37 changes: 37 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
address String @id
deposits Int @default(0)
partialBlobs PartialBlob[]
}

model PartialBlob {
id Int @id @default(autoincrement())
bid Int
signature String
data Bytes
fromAddress String
owner User @relation(fields: [fromAddress], references: [address])
fusedBlob FusedBlob? @relation(fields: [fusedBlobId], references: [id])
fusedBlobId Int? // Might be null if not yet included
fusedBlobPosition Int? // ""
cost Int? // ""
}

model FusedBlob {
id Int @id @default(autoincrement())
txHash String? // Might be null until sent to network
totalCost Int?
partialBlobs PartialBlob[]
}

0 comments on commit 455f60b

Please sign in to comment.