Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/retention.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,9 @@ psql $DATABASE_URL -c "\dt retention_*"
- Security Team: security@liquifact.com
- Legal Compliance: legal@liquifact.com
- Engineering Lead: eng@liquifact.com

## Concurrency Control & Security
Legal hold creation is now protected by a partial unique index (`unique_active_legal_hold_per_invoice`).
- This enforces at-most-one active hold per invoice at the database level.
- Concurrent requests that attempt to create duplicate holds will be rejected by PostgreSQL with a `SequelizeUniqueConstraintError`.
- The application layer maps this to a `409 Conflict` response.
15 changes: 15 additions & 0 deletions migrations/20260630084500_add_unique_active_hold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addIndex('legal_holds', ['invoice_id'], {
unique: true,
where: {
active: true,
expires_at: { [Sequelize.Op.gt]: Sequelize.literal('NOW()') }
},
name: 'unique_active_legal_hold_per_invoice'
});
},
down: async (queryInterface) => {
await queryInterface.removeIndex('legal_holds', 'unique_active_legal_hold_per_invoice');
}
};
Loading
Loading