-
Notifications
You must be signed in to change notification settings - Fork 63
Preliminary Design of Trigger Binding #9
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
Conversation
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.
Nice to see this progress! Some quick comments based on what I've read so far:
samples/SqlExtensionSamples/TriggerBindingSamples/ProductsTrigger.cs
Outdated
Show resolved
Hide resolved
samples/SqlExtensionSamples/TriggerBindingSamples/ProductsTrigger.cs
Outdated
Show resolved
Hide resolved
samples/SqlExtensionSamples/TriggerBindingSamples/ProductsTrigger.cs
Outdated
Show resolved
Hide resolved
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.
Round two of feedback. I still have more code to get through but hopefully this is useful feedback to start thinking about.
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.
wow, this was a lot of code. Overall, really nice job. Super exciting that you've gotten this working!! :)
Main points:
- I'm worried about how many SQL commands we have to run to retrieve all of the data, renew/acquire/release leases, etc. Have you had a chance to stress test this (particularly with more than one Functions host running at once?)
- Partially in response to ^, I think we should support some type of
IEnumerable<SqlChangeTrackingEntry>
to reduce at least some of the trips to SQL - More tests/examples
[SqlTrigger("Products", ConnectionStringSetting = "SqlConnectionString")] IEnumerable<SqlChangeTrackingEntry<Product>> changes, | ||
ILogger logger) | ||
{ | ||
foreach (var change in changes) |
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.
We should try to come up with more complicated examples (+ tests) that use the Trigger to make sure we've covered a wide range of customer scenarios. @anthonychu might be able to help with this, but some ideas:
-
trigger plus input binding to retrieve data about the rows that have changed (not just the PKs). Maybe we trigger on changes to the Customers table, retrieve data about the Customer using the input binding, and then send a welcome "email" if it's an insert
-
trigger where order matters. Say we're triggering on changes to the Orders table, which has a Foreign Key to the Customers table. One use case could be to process all the changes to a particular Customer in order. I don't think we support this today, but it would be good to keep it in mind / have as a goal if we think users might want this
/// <returns>The query</returns> | ||
private async Task<string> BuildCreateTableCommandStringAsync() | ||
{ | ||
await GetPrimaryKeysAsync(); |
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.
things are going to get really weird if the customer changes the PKs on their user table.. although I guess the change tracking table will also get messed up - do you know how SQL handles that?
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 thought about this as well. I couldn't find anything in the Change Tracking docs about this, but when I tried to change the primary key constraint on one of my tables by first deleting it and then creating another constraint, Change Tracking prevented me from deleting it. From what I understand, this is the only way to mess with primary key constraints since it doesn't seem like you can add another primary key constraint after one already exists. That's what this doc made it seem like at least.
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've reviewed everything except SqlTableWatcher.cs (I wanted to save that one for last 😄). See feedback below - mostly minor stylistic stuff.
samples/SqlExtensionSamples/InputBindingSamples/GetProductsSqlCommand.cs
Outdated
Show resolved
Hide resolved
samples/SqlExtensionSamples/OutputBindingSamples/AddProductsArray.cs
Outdated
Show resolved
Hide resolved
samples/SqlExtensionSamples/OutputBindingSamples/AddProductsAsyncCollector.cs
Outdated
Show resolved
Hide resolved
samples/SqlExtensionSamples/TriggerBindingSamples/ProductsTrigger.cs
Outdated
Show resolved
Hide resolved
Preliminary Design of Trigger Binding
Outlines the preliminary design of the trigger binding, including
I still haven't implemented functionality to periodically cleanup the worker table (similar to how SQL cleans up the change table). And I haven't started any work related to the scale controller.
Design doc that the trigger binding is based on.