-
Notifications
You must be signed in to change notification settings - Fork 11
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
Bendyworks/deduplicate starting salary #267
Open
rogerroelofs
wants to merge
18
commits into
main
Choose a base branch
from
bendyworks/deduplicate-starting-salary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6e4e44d
#206 WIP start removing starting salary from employee into salaries
04d0594
#206 move salaries to relate to tenures
62e971e
#206 restore edit message for first salary
21b0a89
#206 WIP start removing starting salary from employee into salaries
8eed07d
#206 WIP merge in moving salaries to tenures
69a0538
#206 update specs to match new salary data structure
afd6345
Merge branch 'main' into bendyworks/deduplicate-starting-salary
e733471
#206 improve employee factory and make specs match
032333a
#206 make rails_best_practice happy
8ee9daa
#206 get salary start date from tenure rather than from a hidden field
1a3ff98
#206 WIP change how starting salary UI works
rogerroelofs 13f90d8
#206 WIP add after save to keep tenure and salary dates in sync and f…
rogerroelofs 2993f4b
#206 update cucumber tests
rogerroelofs beea651
#206 commit last change I missed
rogerroelofs 6e0ec6c
#206 rails_best_practice updates
rogerroelofs 23ae144
Merge remote-tracking branch 'origin/main' into bendyworks/deduplicat…
rogerroelofs f5994ef
#206 simplify haml interpolation
rogerroelofs 613bf44
Merge branch 'main' into bendyworks/deduplicate-starting-salary
rogerroelofs 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
42 changes: 42 additions & 0 deletions
42
db/migrate/20210315122533_migrate_starting_salary_to_salaries.rb
This file contains 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,42 @@ | ||
class MigrateStartingSalaryToSalaries < ActiveRecord::Migration[6.1] | ||
def up | ||
add_reference :salaries, :tenure, foreign_key: true | ||
|
||
Employee.all.each do |employee| | ||
Salary.where(employee_id: employee.id).all.each do |salary| | ||
# look for tenure date range containing salary start_date. Fall back to first if none found | ||
tenure = employee.tenures.where( | ||
'start_date <= :date and (end_date >= :date or end_date is NULL)', | ||
date: salary.start_date).first | ||
tenure = employee.tenures.first unless tenure | ||
salary.update(tenure_id: tenure.id) | ||
end | ||
tenure = employee.tenures.first | ||
tenure.salaries << Salary.new( | ||
start_date: tenure.start_date, | ||
annual_amount: employee.attributes['starting_salary'], | ||
employee_id: employee.id) | ||
tenure.save! | ||
end | ||
|
||
remove_reference :salaries, :employee, foreign_key: true | ||
remove_column :employees, :starting_salary | ||
end | ||
|
||
def down | ||
add_column :employees, :starting_salary, :decimal, default: 0, null: false | ||
add_reference :salaries, :employee, foreign_key: true | ||
|
||
Employee.all.each do |employee| | ||
employee.tenures.each do |tenure| | ||
tenure.salaries.each { |salary| salary.update(employee_id: employee.id) } | ||
end | ||
tenure = employee.tenures.first | ||
salary = tenure.salaries.first if tenure | ||
employee.update(starting_salary: salary.annual_amount) if salary | ||
salary.destroy! | ||
end | ||
|
||
remove_reference :salaries, :tenure | ||
end | ||
end |
This file contains 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
Oops, something went wrong.
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.
I don't love this but I was having trouble making the employee model validate on create.
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 wonder if this validation could be handled in a
before_action
method?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 adding
:inverse_of
to thesalary
model fix this?rails/rails#8828