-
Notifications
You must be signed in to change notification settings - Fork 44.8k
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
feat(backend): Add graph/node id & execution id on CreditTransaction table #9217
base: zamilmajdy/secrt-1014-scalability-implement-transactions-snapshotting
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
ALTER TABLE "CreditTransaction" DROP CONSTRAINT "CreditTransaction_blockId_fkey"; | ||
|
||
-- Update migrate blockId into metadata->"block_id" | ||
UPDATE "CreditTransaction" SET "metadata" = jsonb_set("metadata"::jsonb, '{block_id}', to_jsonb("blockId")) WHERE "blockId" IS NOT NULL; |
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.
model CreditTransaction {
// ...
metadata Json?
}
Does jsonb_set("metadata"::jsonb, ...)
work if metadata
is currently NULL
?
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.
Robot says to use COALESCE("metadata"::jsonb, '{}')
:
UPDATE "CreditTransaction" SET "metadata" = jsonb_set("metadata"::jsonb, '{block_id}', to_jsonb("blockId")) WHERE "blockId" IS NOT NULL; | |
UPDATE "CreditTransaction" | |
SET "metadata" = jsonb_set( | |
COALESCE("metadata"::jsonb, '{}'), | |
'{block_id}', | |
to_jsonb("blockId") | |
) | |
WHERE "blockId" IS NOT NULL; |
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.
I understand we can't make data out of thin air, but can we still use an actual column for node_execution_id
? These columns can be optional for now, and I think we should be able to make them non-optional (and archive old CreditTransactions
to a different place, e.g. a different table or some other system) after closing off the current fiscal year.
The transaction is not always related to the node execution. It can be a top-up, or any random adjustments. Or maybe another custom transaction. So there is no way to make it non-optional. What's the need for the actual column? I can add an auto generate column value from the metadata column if you really need to have it materialized, e.g:
And add the 'nodeExecId` in prisma schena as an actual column or even index it. |
Ack on this table not being for just node execution credit transactions, I was missing that bit of context. My concern is that "informal" relationships which aren't stored in actual columns means we can't use Prisma to query them together afaik. If we can make that work with one of the solutions you proposed I'm happy. |
Yes, adding
on the schema, and
on the migration, works, if needed in the future. But I still think not doing it and querying directly using Prima still be a simpler choice: Unless we really have a strong use case of querying it through a relational entity, do we actually need that? can't we just query those separately? |
We need to be able to determine the cost of graph/node execution.
Changes 🏗️
metadata
column:blockId
column and backfill the dropped value into metadata->>block_id.