-
Notifications
You must be signed in to change notification settings - Fork 155
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
chore(electric,client): Create new protocol op to represent a compensation #639
Changes from 7 commits
5541e6c
6e9ed3c
4369842
906d3bd
a5abed4
f7ba362
439a7cd
fde977b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@core/electric": patch | ||
"electric-sql": patch | ||
--- | ||
|
||
[VAX-1335] Create new protocol op to represent a compensation |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,10 +118,9 @@ export function generateOplogTriggers( | |
/** | ||
* Generates triggers for compensations for all foreign keys in the provided table. | ||
* | ||
* Compensation is recorded as a specially-formatted update. It acts as a no-op, with | ||
* previous value set to NULL, and it's on the server to figure out that this is a no-op | ||
* compensation operation (usually `UPDATE` would have previous row state known). The entire | ||
* reason for it existing is to maybe revive the row if it has been deleted, so we need correct tags. | ||
* Compensation is recorded as a SatOpCompensation messaage. The entire reason | ||
* for it existing is to maybe revive the row if it has been deleted, so we need | ||
* correct tags. | ||
* | ||
* The compensation update contains _just_ the primary keys, no other columns are present. | ||
* | ||
|
@@ -155,7 +154,7 @@ function generateCompensationTriggers(table: Table): Statement[] { | |
1 == (SELECT value from _electric_meta WHERE key == 'compensations') | ||
BEGIN | ||
INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp) | ||
SELECT '${fkTableNamespace}', '${fkTableName}', 'UPDATE', json_object(${joinedFkPKs}), json_object(${joinedFkPKs}), NULL, NULL | ||
SELECT '${fkTableNamespace}', '${fkTableName}', 'COMPENSATION', json_object(${joinedFkPKs}), json_object(${joinedFkPKs}), NULL, NULL | ||
FROM "${fkTableNamespace}"."${fkTableName}" WHERE "${foreignKey.parentKey}" = new."${foreignKey.childKey}"; | ||
END; | ||
`, | ||
|
@@ -167,7 +166,7 @@ function generateCompensationTriggers(table: Table): Statement[] { | |
1 == (SELECT value from _electric_meta WHERE key == 'compensations') | ||
BEGIN | ||
INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp) | ||
SELECT '${fkTableNamespace}', '${fkTableName}', 'UPDATE', json_object(${joinedFkPKs}), json_object(${joinedFkPKs}), NULL, NULL | ||
SELECT '${fkTableNamespace}', '${fkTableName}', 'COMPENSATION', json_object(${joinedFkPKs}), json_object(${joinedFkPKs}), NULL, NULL | ||
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. do we need to handle client updates (i.e. reapply these triggers)? 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. yes we would, good point. off the top of your head, is there a mechanism in place to trigger (😉 ) the re-creation of the triggers? 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. @icehaunter looking at the client it seems that adding re-application of these triggers on boot is a fairly major change. are we comfortable with postponing that feature for the moment considering that this change is backwards compatible with existing trigger implementations? 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. |
||
FROM "${fkTableNamespace}"."${fkTableName}" WHERE "${foreignKey.parentKey}" = new."${foreignKey.childKey}"; | ||
END; | ||
`, | ||
|
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.
That's a
minor
on both, since you're introducing a cross-cutting feature that makes new clients incompatible with old server.sThere 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.
wasn't sure how we handled the version change now there's no version in the handshake or the protocol
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.
There is, it's just a bit hidden. It's sent in HTTP headers in WebSocket upgrade request.