-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Drop foreign key constraint on order id
The order and the matches are persisted by async actors. It can happen that the market order has not yet been persisted when the match is processed. Thus it could happen that the matches table is persisted before the order has been persisted, which resulted in a foreign key violation. By dropping the foreign key we don't care if the order is already persisted and can continue with eventual consistency. I think this is the better option than to synchronize the two inserts as we are anyways aiming for decoupling the orderbook from the coordinator.
- Loading branch information
Showing
3 changed files
with
28 additions
and
17 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
.../migrations/2024-06-07-105918_drop_foreign_key_constraint_to_order_id_on_matches/down.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,9 @@ | ||
ALTER TABLE "matches" | ||
ADD CONSTRAINT matches_order_id_fkey | ||
FOREIGN KEY (order_id) | ||
REFERENCES orders (order_id); | ||
|
||
ALTER TABLE "matches" | ||
ADD CONSTRAINT matches_match_order_id_fkey | ||
FOREIGN KEY (match_order_id) | ||
REFERENCES orders (order_id); |
2 changes: 2 additions & 0 deletions
2
...or/migrations/2024-06-07-105918_drop_foreign_key_constraint_to_order_id_on_matches/up.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,2 @@ | ||
ALTER TABLE "matches" DROP CONSTRAINT matches_order_id_fkey; | ||
ALTER TABLE "matches" DROP CONSTRAINT matches_match_order_id_fkey; |
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