-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add provider integration database schema #593
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...ersistence/schema/migrations/20241203141912_add_provider_integration_tables/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
-- CreateTable | ||
CREATE TABLE "provider_wallet" ( | ||
"id" TEXT NOT NULL, | ||
"label" TEXT, | ||
"client_id" TEXT NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"external_id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "provider_wallet_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_account" ( | ||
"id" TEXT NOT NULL, | ||
"label" TEXT, | ||
"client_id" TEXT NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"external_id" TEXT NOT NULL, | ||
"wallet_id" TEXT NOT NULL, | ||
"network_id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "provider_account_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_address" ( | ||
"id" TEXT NOT NULL, | ||
"client_id" TEXT NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"external_id" TEXT NOT NULL, | ||
"account_id" TEXT NOT NULL, | ||
"address" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "provider_address_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_address_book" ( | ||
"id" TEXT NOT NULL, | ||
"client_id" TEXT NOT NULL, | ||
"connection_id" TEXT NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"external_id" TEXT NOT NULL, | ||
"external_classification" TEXT, | ||
"address" TEXT NOT NULL, | ||
"asset_id" TEXT, | ||
"network_id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "provider_address_book_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_connection" ( | ||
"id" TEXT NOT NULL, | ||
"client_id" TEXT NOT NULL, | ||
"provider" TEXT NOT NULL, | ||
"url" TEXT NOT NULL, | ||
"label" TEXT, | ||
"credentials" JSONB NOT NULL, | ||
"status" TEXT NOT NULL, | ||
"_integrity" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
"revoked_at" TIMESTAMP(3), | ||
|
||
CONSTRAINT "provider_connection_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_wallet_connection" ( | ||
"client_id" TEXT NOT NULL, | ||
"connection_id" TEXT NOT NULL, | ||
"wallet_id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "provider_wallet_connection_pkey" PRIMARY KEY ("client_id","connection_id","wallet_id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_sync" ( | ||
"id" TEXT NOT NULL, | ||
"client_id" TEXT NOT NULL, | ||
"connection_id" TEXT NOT NULL, | ||
"status" TEXT NOT NULL, | ||
"error_name" TEXT, | ||
"error_message" TEXT, | ||
"error_trace_id" TEXT, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"completed_at" TIMESTAMP(3), | ||
|
||
CONSTRAINT "provider_sync_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "provider_transfer" ( | ||
"id" TEXT NOT NULL, | ||
"client_id" TEXT NOT NULL, | ||
"source_wallet_id" TEXT, | ||
"source_account_id" TEXT, | ||
"source_address_id" TEXT, | ||
"provider" TEXT NOT NULL, | ||
"external_id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "provider_transfer_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_account" ADD CONSTRAINT "provider_account_wallet_id_fkey" FOREIGN KEY ("wallet_id") REFERENCES "provider_wallet"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_address" ADD CONSTRAINT "provider_address_account_id_fkey" FOREIGN KEY ("account_id") REFERENCES "provider_account"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_address_book" ADD CONSTRAINT "provider_address_book_connection_id_fkey" FOREIGN KEY ("connection_id") REFERENCES "provider_connection"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_wallet_connection" ADD CONSTRAINT "provider_wallet_connection_connection_id_fkey" FOREIGN KEY ("connection_id") REFERENCES "provider_connection"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_wallet_connection" ADD CONSTRAINT "provider_wallet_connection_wallet_id_fkey" FOREIGN KEY ("wallet_id") REFERENCES "provider_wallet"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_sync" ADD CONSTRAINT "provider_sync_connection_id_fkey" FOREIGN KEY ("connection_id") REFERENCES "provider_connection"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_transfer" ADD CONSTRAINT "provider_transfer_source_wallet_id_fkey" FOREIGN KEY ("source_wallet_id") REFERENCES "provider_wallet"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_transfer" ADD CONSTRAINT "provider_transfer_source_account_id_fkey" FOREIGN KEY ("source_account_id") REFERENCES "provider_account"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "provider_transfer" ADD CONSTRAINT "provider_transfer_source_address_id_fkey" FOREIGN KEY ("source_address_id") REFERENCES "provider_address"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
provider = "prisma-client-js" | ||
binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x"] | ||
// Output into a separate subdirectory so multiple schemas can be used in a | ||
// monorepo. | ||
// | ||
// Reference: https://github.com/nrwl/nx-recipes/tree/main/nestjs-prisma | ||
output = "../../../../../../../node_modules/@prisma/client/vault" | ||
output = "../../../../../../../node_modules/@prisma/client/vault" | ||
} | ||
|
||
datasource db { | ||
|
@@ -14,7 +14,7 @@ datasource db { | |
} | ||
|
||
model Vault { | ||
id String @id | ||
id String @id | ||
masterKey String? @map("master_key") | ||
adminApiKey String? @map("admin_api_key") | ||
|
||
|
@@ -24,10 +24,145 @@ model Vault { | |
// TODO: (@wcalderipe, 12/03/23) use hstore extension for better performance. | ||
// See https://www.postgresql.org/docs/9.1/hstore.html | ||
model KeyValue { | ||
key String @id | ||
clientId String? @map("client_id") | ||
collection String | ||
value String | ||
key String @id | ||
clientId String? @map("client_id") | ||
collection String | ||
value String | ||
|
||
@@map("key_value") | ||
} | ||
|
||
model ProviderWallet { | ||
id String @id | ||
label String? | ||
clientId String @map("client_id") | ||
provider String | ||
externalId String @map("external_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
|
||
accounts ProviderAccount[] | ||
connections ProviderWalletConnection[] | ||
transfers ProviderTransfer[] @relation("SourceWallet") | ||
|
||
@@map("provider_wallet") | ||
} | ||
|
||
model ProviderAccount { | ||
id String @id | ||
label String? | ||
clientId String @map("client_id") | ||
provider String | ||
externalId String @map("external_id") | ||
walletId String @map("wallet_id") | ||
networkId String @map("network_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
|
||
wallet ProviderWallet @relation(fields: [walletId], references: [id]) | ||
addresses ProviderAddress[] | ||
transfers ProviderTransfer[] @relation("SourceAccount") | ||
|
||
@@map("provider_account") | ||
} | ||
|
||
model ProviderAddress { | ||
id String @id | ||
clientId String @map("client_id") | ||
provider String | ||
externalId String @map("external_id") | ||
accountId String @map("account_id") | ||
address String | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
|
||
account ProviderAccount @relation(fields: [accountId], references: [id]) | ||
transfers ProviderTransfer[] @relation("SourceAddress") | ||
|
||
@@map("provider_address") | ||
} | ||
|
||
model ProviderAddressBook { | ||
id String @id | ||
clientId String @map("client_id") | ||
connectionId String @map("connection_id") | ||
provider String | ||
externalId String @map("external_id") | ||
externalClassification String? @map("external_classification") | ||
address String | ||
assetId String? @map("asset_id") | ||
networkId String @map("network_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
|
||
connection ProviderConnection @relation(fields: [connectionId], references: [id]) | ||
|
||
@@map("provider_address_book") | ||
} | ||
|
||
model ProviderConnection { | ||
id String @id | ||
clientId String @map("client_id") | ||
provider String | ||
url String | ||
label String? | ||
credentials Json | ||
status String | ||
integrity String @map("_integrity") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
revokedAt DateTime? @map("revoked_at") | ||
|
||
counterparties ProviderAddressBook[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "addressBookEntries" is the other option, but I found the term long. Happy to change it back. |
||
connections ProviderWalletConnection[] | ||
syncs ProviderSync[] | ||
|
||
@@map("provider_connection") | ||
} | ||
|
||
model ProviderWalletConnection { | ||
clientId String @map("client_id") | ||
connectionId String @map("connection_id") | ||
walletId String @map("wallet_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
|
||
connection ProviderConnection @relation(fields: [connectionId], references: [id]) | ||
wallet ProviderWallet @relation(fields: [walletId], references: [id]) | ||
|
||
@@id([clientId, connectionId, walletId]) | ||
@@map("provider_wallet_connection") | ||
} | ||
|
||
model ProviderSync { | ||
id String @id | ||
clientId String @map("client_id") | ||
connectionId String @map("connection_id") | ||
status String | ||
errorName String? @map("error_name") | ||
errorMessage String? @map("error_message") | ||
errorTraceId String? @map("error_trace_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
completedAt DateTime? @map("completed_at") | ||
|
||
// Relations | ||
connection ProviderConnection @relation(fields: [connectionId], references: [id]) | ||
|
||
@@map("provider_sync") | ||
} | ||
|
||
model ProviderTransfer { | ||
id String @id | ||
clientId String @map("client_id") | ||
sourceWalletId String? @map("source_wallet_id") | ||
sourceAccountId String? @map("source_account_id") | ||
sourceAddressId String? @map("source_address_id") | ||
provider String | ||
externalId String @map("external_id") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
|
||
wallet ProviderWallet? @relation("SourceWallet", fields: [sourceWalletId], references: [id]) | ||
account ProviderAccount? @relation("SourceAccount", fields: [sourceAccountId], references: [id]) | ||
address ProviderAddress? @relation("SourceAddress", fields: [sourceAddressId], references: [id]) | ||
|
||
@@map("provider_transfer") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prisma doesn't let me name the column with an
_
prefix.