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

fix(api): add reorg handling fixes #643

Merged
merged 10 commits into from
Nov 25, 2024
Prev Previous commit
Next Next commit
feat(db): add address category info fks constraints tx model
PJColombo committed Nov 20, 2024
commit 20b6a6e7530e96a41bc89c6fb6068e979833f146
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AddForeignKey
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_from_id_category_fkey" FOREIGN KEY ("from_id", "category") REFERENCES "address_category_info"("address", "category") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_to_id_category_fkey" FOREIGN KEY ("to_id", "category") REFERENCES "address_category_info"("address", "category") ON DELETE RESTRICT ON UPDATE CASCADE;
16 changes: 10 additions & 6 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
generator client {
provider = "prisma-client-js"
// rhel-openssl-1.0.x is required by Vercel
binaryTargets = ["native", "rhel-openssl-1.0.x", "linux-musl-openssl-3.0.x"]
binaryTargets = ["native", "rhel-openssl-1.0.x", "linux-musl-openssl-3.0.x"]
previewFeatures = ["tracing", "metrics", "typedSql"]
}

@@ -83,7 +83,9 @@ model AddressCategoryInfo {
firstBlockNumberAsReceiver Int? @map("first_block_number_as_receiver")
firstBlockNumberAsSender Int? @map("first_block_number_as_sender")

addressEntity Address @relation(fields: [address], references: [address])
addressEntity Address @relation(fields: [address], references: [address])
transactionsAsSender Transaction[] @relation("senderAddressCategoryInfoRelation")
transactionsAsReceiver Transaction[] @relation("receiverAddressCategoryInfoRelation")

@@unique([address, category])
@@map("address_category_info")
@@ -176,10 +178,12 @@ model Transaction {
updatedAt DateTime @default(now()) @map("updated_at")
decodedFields Json @default("{}") @map("decoded_fields")

blobs BlobsOnTransactions[]
block Block @relation(fields: [blockHash], references: [hash])
from Address @relation("senderAddressRelation", fields: [fromId], references: [address])
to Address @relation("receiverAddressRelation", fields: [toId], references: [address])
blobs BlobsOnTransactions[]
block Block @relation(fields: [blockHash], references: [hash])
from Address @relation("senderAddressRelation", fields: [fromId], references: [address])
to Address @relation("receiverAddressRelation", fields: [toId], references: [address])
fromAddressCategoryInfo AddressCategoryInfo @relation("senderAddressCategoryInfoRelation", fields: [fromId, category], references: [address, category])
toAddressCategoryInfo AddressCategoryInfo @relation("receiverAddressCategoryInfoRelation", fields: [toId, category], references: [address, category])

transactionForks TransactionFork[]