Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Refactor fairly static text into ActiveRecord Models #1742

Merged
merged 16 commits into from
Sep 19, 2019
Merged

Refactor fairly static text into ActiveRecord Models #1742

merged 16 commits into from
Sep 19, 2019

Conversation

pgwillia
Copy link
Member

@pgwillia pgwillia commented Aug 9, 2019

  • Creates migrations for Status, ItemType, CirculationRule, Library and Locations. These migrations also create today's data in the db.
  • refactor to use the new ActiveRecord objects

These tables will populate information in this table
Screenshot from 2019-09-19 12-47-54
And the UAL shield in the results
Screenshot from 2019-09-19 14-08-37

Out of scope:

#1273

@ualbertalib-bot
Copy link

ualbertalib-bot commented Aug 9, 2019

1 Warning
⚠️ This PR is too big! Consider breaking it down into smaller PRs.

Generated by 🚫 Danger

@pgwillia pgwillia changed the title WIP - Refactor fairly static text into ActiveRecord Models Refactor fairly static text into ActiveRecord Models Sep 3, 2019
@pgwillia
Copy link
Member Author

pgwillia commented Sep 3, 2019

Something is up with my db:migration. I'll take a look tomorrow, I guess still a WIP.

@pgwillia pgwillia changed the title Refactor fairly static text into ActiveRecord Models WIP Refactor fairly static text into ActiveRecord Models Sep 3, 2019
@pgwillia pgwillia changed the title WIP Refactor fairly static text into ActiveRecord Models Refactor fairly static text into ActiveRecord Models Sep 5, 2019
@pgwillia
Copy link
Member Author

pgwillia commented Sep 5, 2019

Something is up with my db:migration. I'll take a look tomorrow, I guess still a WIP.

The Locations ActiveRecord object was loaded by the migration potentially before it is created. I moved the initialization of the UAL_SHIELD_LIBRARY constants to that class rather than having it in a helper.

I think this is ready for review.

weiweishi
weiweishi previously approved these changes Sep 12, 2019
Copy link
Contributor

@weiweishi weiweishi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. But I wouldn't mind @mbarnett and @redlibrarian's review and opinions.

@@ -17,7 +17,21 @@ def holdings(document, method)
end

def symphony_status(item)
SYMPHONY_STATUSES[item[:status].downcase.underscore.to_sym]
Status.find_by!(short_code: item[:status].downcase.underscore).name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does find_by! do, difference with find_by?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_by! will throw an exception if there are no results, whereas find_by will return nil

Copy link

@mbarnett mbarnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure that seeds are the right way to load this data (not 100% sure they're the wrong way, either, I'm just not sure what "db:seed will seed the current data (This will be important information when this gets handed to @nmacgreg )" means).

If this is data that's only being loaded when spinning up fresh databases, seeds are a good approach. If this data is going to be added to an existing production DB, doing it in a migration instead is probably going to be cleaner.

SYMPHONY_STATUSES[item[:status].downcase.underscore.to_sym]
Status.find_by!(short_code: item[:status].downcase.underscore).name
rescue ActiveRecord::RecordNotFound
'Unknown'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to Weiwei's comment, I just want to sanity check this approach since I don't know the exact details of the problem being solved here:

If 'Unknown' is expected to come up regularly, then we're using exceptions for control flow here and it might be better to do something like

Status.find_by(short_code: item[:status].downcase.underscore).name || 'Unknown'

instead.

If this is just to provide some kind of sane default in a scenario we don't expect to happen only in case of some bug where something has a broken status (ie, if this is expected to be an exceptional circumstance), then this totally makes sense.

Either way works, it just depends on which intention we want to signal to future readers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had decided "if an id is looked up that doesn't exist catch in rollbar and use 'Unknown' temporarily" #1273 (comment). Looks like I missed the Rollbar part. I'll leave it as an exception.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, just wanted to be sure.

app/helpers/holdings_helper.rb Outdated Show resolved Hide resolved
@pgwillia
Copy link
Member Author

Not 100% sure that seeds are the right way to load this data (not 100% sure they're the wrong way, either, I'm just not sure what "db:seed will seed the current data (This will be important information when this gets handed to @nmacgreg )" means).

If this is data that's only being loaded when spinning up fresh databases, seeds are a good approach. If this data is going to be added to an existing production DB, doing it in a migration instead is probably going to be cleaner.

It didn't occur to me that loading data in a migration was even a thing. It does make sense to do it that way because our intention is that the data is a capture from a point in time and will become out of date. If it's a seed then the expectation would be that it should be kept up.

- moved db content creation to migration
- added rollbar message to unknown exception rescues
- prefer #detect to returns within #each
@pgwillia pgwillia requested a review from mbarnett September 19, 2019 20:09
Copy link

@mbarnett mbarnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny nit on the more complicated not ... is nil? being simplifiable to present?

app/helpers/holdings_helper.rb Outdated Show resolved Hide resolved
Copy link

@mbarnett mbarnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff

@pgwillia pgwillia merged commit 9f00f02 into ualbertalib:master Sep 19, 2019
@pgwillia pgwillia deleted the 1273_refactor_yaml_data branch September 19, 2019 21:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants