-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): improve PSQL balance calculation (#2881)
* chore(backend): add check constraint to ledger transfers * feat(backend): update balance calculation to use psql query
- Loading branch information
Showing
4 changed files
with
84 additions
and
31 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/backend/migrations/20240820161040_add_ledger_transfer_constraint.js
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,23 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return knex.schema.table('ledgerTransfers', function (table) { | ||
table.check( | ||
`("state" != 'PENDING') OR ("expiresAt" IS NOT NULL)`, | ||
null, | ||
'check_pending_requires_expires_at' | ||
) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.table('ledgerTransfers', function (table) { | ||
table.dropChecks(['check_pending_requires_expires_at']) | ||
}) | ||
} |
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