-
Notifications
You must be signed in to change notification settings - Fork 43
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
Monitors setup migrations #1495
Monitors setup migrations #1495
Conversation
… are distinguished in terms of database by meta.db_table_comment
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.
Everything looks good to me @york-stsci thank you for this. Just a few questions and comments before I approve.
...te/apps/jwql/migrations/0017_centralstorage_fgsanomaly_filesystemcharacteristics_and_more.py
Outdated
Show resolved
Hide resolved
...te/apps/jwql/migrations/0018_centralstorage_fgsanomaly_filesystemcharacteristics_and_more.py
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.
LGTM
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.
Great work so far @york-stsci, I do have some feedback that we can discuss. Most of these comments are in the code review, but I want to consolidate them here with a few overall additions so my feedback is cohesive.
-
The
MonitorRouter
class should be in its own file called router.py and not associated with thecommon_monitor
functionality. This router is a system wide addition (apologies, as this comment should have been addressed in the previous PR). I personally thinkrouter.py
should live parallel tomodels.py
however if you choose to keep it in the sub folder thats fine. I’ll continue my explanation assuming it is up a level for brevity. -
We also need to set django up to see our
router.py
as part of its settings. Otherwise it will just sit there as a class. In order to do this we need to updatejwql/website/jwql_proj/settings.py
by adding the path to our routerDATABASE_ROUTERS = ['jwql.router.monitor_router']
At this point, all db access defined inMonitorRouter
should be automatically handled by django. -
db_table_comment
is being used functionally to associate models with databases. This is a clever workaround but not the intended use of this field.db_table_comment
should be used “for documenting database tables for individuals with direct database access who may not be looking at your Django code.” We should putapp_label
back. I’m also not sure ifapp_label
should bemonitors
orjwql
, as we don’t have a separate monitors app associated with this repository (which is why I’d leanjwql
). -
If we aren’t using
db_table_comment
to align the models with their respective db, we should use the monitor model names from a list that should be defined inconstants.py
. This list will be accessed inside theMonitorRouter
class. An example of how this would be done is:
from constants import monitor_models
def db_for_read(self, model, **hints):
if model._meta.app_label == ‘jwql’:
if model.__name__ in monitor_models:
return ‘monitors’
return None
Note: the above suggestion should be applied to all elements in the router, with the exception of allow_migrate which will use the parameter model_name
instead of model.__name__
Happy to discuss further if you like!
...te/apps/jwql/migrations/0017_centralstorage_fgsanomaly_filesystemcharacteristics_and_more.py
Outdated
Show resolved
Hide resolved
...te/apps/jwql/migrations/0018_centralstorage_fgsanomaly_filesystemcharacteristics_and_more.py
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.
@york-stsci Look great! Only thing I see is to change the plot_type=='model'
cell back to this:
if plot_type == 'model':
plot_data = df['median'].values / df['total_bkg'].values
Hello @york-stsci, Thank you for updating ! Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated at 2024-02-23 19:07:07 UTC |
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.
Thanks Brian! Few small bugs I noticed
Note that, for databases other than dev, we might need to fake migration 17, because we can't use |
And this is the part where I realize that I ran the migrations before updating the router class. Hang on whilst I rock the boat (i.e. roll back, then forward, repeat as required) |
Logging this here for reference: It is entirely possible that migration 17 will fail when run with |
I am good with this @BradleySappington seems happy as well as @bsunnquist. @york-stsci let me know when this is ready to merge. |
I'd like @BradleySappington to take another look at the current form, just to backstop me, and then I think we're good. |
I think this is a great idea. @BradleySappington let me know when you are finished with your review and we can get this in! |
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.
Great work Brian
This PR officially adds the monitors tables to the migrations folder, adds two columns to the NIRCam claw monitor, and filters out NIRCam claw images by date during the database query rather than after retrieval.