-
Notifications
You must be signed in to change notification settings - Fork 35
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
Partition work_orders #1392
base: main
Are you sure you want to change the base?
Partition work_orders #1392
Conversation
end | ||
|
||
def drop_partition(parent, partition) do | ||
unless valid_chars?(parent) && valid_chars?(partition) do |
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.
String interpolation in queries makes me nervous :)- so I added some simple validation against the more obvious forms of injection (as I know that we can't bind params in DDL statements) just in case this method ends up being used someplace else.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1392 +/- ##
==========================================
+ Coverage 86.08% 86.16% +0.07%
==========================================
Files 218 220 +2
Lines 6452 6496 +44
==========================================
+ Hits 5554 5597 +43
- Misses 898 899 +1 ☔ View full report in Codecov by Sentry. |
52ce270
to
3411599
Compare
end | ||
|
||
@impl Oban.Worker | ||
def perform(%Oban.Job{args: %{"drop_older_than" => %{"weeks" => weeks}}}) |
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 could not get this method to work as originally implemented in platform so I modelled the arguments on the other perform
variant.
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.
Ah interesting, this looks good to me though :)
end | ||
end | ||
|
||
defp all_relations() do |
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 ended up with a fair number of functions to manage the fixtures - so of which have overlaps. If the overlaps are resolved I am hoping that I could reduce the number of fixture methods.
However, I will need to extend (at least) the scenarios that cover :all
use case as I partition the other tables - as such I was hoping to delay the cleanup until those scenarios have been catered for.
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.
Thats cool, if the functions end up living in this test file thats all good imo.
@@ -0,0 +1,17 @@ | |||
defmodule Lightning.AdminTools do | |||
def generate_iso_weeks(start_date, end_date) do | |||
Date.range(start_date, end_date) |
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.
When I was setting up tests for this class, I noticed that there was a small edge case that emerged when dates that are not mondays are passed in as arguments. I can't imagine that it was a big deal before, but the tweak to fix it was small, so I made an executive decision :).
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 dude! This is awesome, I'll be wanting to test this against a backup of a real db before merging.
Are the migrations idempotent, i.e. if it borks out half way or we have to cancel it (on the unlikely case it takes too long) - will it leave behind a bunch of schemas that must be deleted before running it again? Not saying we have to cater for this right now; but I'd like to know more about the expected sad path.
end | ||
|
||
@impl Oban.Worker | ||
def perform(%Oban.Job{args: %{"drop_older_than" => %{"weeks" => weeks}}}) |
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.
Ah interesting, this looks good to me though :)
@impl Oban.Worker | ||
def perform(%Oban.Job{args: %{"drop_older_than" => %{"weeks" => weeks}}}) | ||
when is_integer(weeks) do | ||
upper_bound = Timex.shift(DateTime.utc_now(), weeks: weeks) |
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.
Could you try using DateTime.shift
instead of Timex - nothing against what you've done here - Timex was the gold standard for all things Date but the built in DateTime has come a long way since then. And we have had issues with Timex in compiled environments (like without having the entire app running, like in migrations on production); if you can achieve a passing test suite by just replacing the use of Timex then we should be good.
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.
3411599
to
8a0199c
Compare
Thanks for all the pointers @stuartc - I tested what I thought would the worst case by inserting a If either of those are no longer true, I am happy to revisit the implementation. I have made the PR changes in a new commit for ease of re-review, if you ping me before you merge I can rebase it into the original commit. |
This PR is being parked, pending a decision on the further partitioning of tables. Amongst other things, this branch contains additional tests and small code tweaks (when compared to the original code) that may be useful when doing date-based partitioning. |
This code needs to still be tested against a database with a significant number of records in the |
Notes for the reviewer
I tried to use as much of the existing functionality from
platform
as possible, to reduce the risk (given that we do add and drop tables). The SQL query that was part ofPartitionTableService.remove_empty
started misbehaving yesterday and I could not get to the bottom of it in a reasonable amount of time, so I decided to extract some of the logic into Elixir.The new methods to support this were added as public methods - I felt that the improved granularity of testing outweighed the polluting of the public API :).
Also, after completing the above change, I realised that I had built a footgun into the code through a beginner's mistake in the elixr code that I added. This resulted in me extending the tests to ensure that they will hopefully catch my next stupid mistake.
Related issue
Fixes #
Review checklist