-
-
Notifications
You must be signed in to change notification settings - Fork 108
Upserting dojo_event_services
table
#140
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c466344
Add a parameter as `expand[]=group`
nalabjp d39c35f
Create `db/dojo_event_services.yaml`
nalabjp cc248ed
Add takizawa' event service
nalabjp bca038c
Implements `dojo_event_services:upsert` task
nalabjp 3c7f24a
Merge remote-tracking branch 'upstream/master' into dojo-event-servic…
nalabjp 92e51ad
`dojo_name` -> `dojo_id`
nalabjp 6d09c2b
Add newcomers
nalabjp d195135
Add group_id for facebook
nalabjp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace :dojo_event_services do | ||
desc '現在のyamlファイルを元にデータベースを更新します' | ||
task upsert: :environment do | ||
puts 'Task as `dojo_event_services:upsert` starting...' | ||
|
||
result = { inserted: [], updated: [], kept: [], skipped: [] } | ||
|
||
list = YAML.load_file(Rails.root.join('db','dojo_event_services.yaml')) | ||
list.each do |des| | ||
unless DojoEventService.names.keys.include?(des['name']) | ||
event_names = DojoEventService.names.keys.map {|s| "`#{s}`" } | ||
result[:skipped] << [des['dojo_name'], "Not used #{event_names.join(' or ')}"] | ||
next | ||
end | ||
|
||
dojo = Dojo.find_by(name: des['dojo_name']) | ||
unless dojo | ||
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.
|
||
result[:skipped] << [des['dojo_name'], 'Not found record in `dojos` table'] | ||
next | ||
end | ||
|
||
insert = false | ||
unless dojo.dojo_event_service | ||
dojo.build_dojo_event_service | ||
insert = true | ||
end | ||
|
||
dojo.dojo_event_service.assign_attributes(des.except('dojo_name')) | ||
if dojo.dojo_event_service.changed? | ||
changes = dojo.dojo_event_service.changes | ||
dojo.dojo_event_service.save! | ||
(insert ? result[:inserted] : result[:updated]) << [des['dojo_name'], changes] | ||
else | ||
result[:kept] << [des['dojo_name']] | ||
end | ||
end | ||
|
||
# Dump result | ||
sorted = result.sort_by {|_, v| v.length }.reverse.to_h | ||
puts | ||
sorted.each do |k, v| | ||
puts "#{k.to_s.camelcase}: #{v.length}" | ||
v.each {|x| puts " #{x.join(': ')}"} | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DojoEventService.names
で定義されているイベントサイトを使っていなければスキップする