Skip to content

Commit

Permalink
ISSUE #448: Threshold of program level and affiliation
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMonardez committed Dec 17, 2024
1 parent f3bd278 commit 87fce7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions db/migrate/20240524135850_create_affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def up
while professor.present?
if professor.institution_id != institution_id
institutions << { institution_id:, start_date:, end_date: }
end_date = start_date
start_date = professor.updated_at
end_date = start_date - 1.month
start_date = professor.updated_at - 1.month
institution_id = professor.institution_id
affiliation = Affiliation.create(
professor: professor,
Expand All @@ -33,7 +33,7 @@ def up
)
else
# Atualiza data de início para data da primeira mudança em que instituição foi definida com esse valor
start_date = professor.updated_at
start_date = professor.updated_at - 1.month
affiliation.update(start_date: start_date)
end
professor = professor.paper_trail.previous_version
Expand All @@ -47,8 +47,8 @@ def down
add_column :professors, :institution_id, :integer
add_index :professors, :institution_id
Professor.all.each do |p|
affiliation = Affiliation.of_professor(p).where(end_date: nil).last
p.update(institution_id: affiliation.institution_id)
affiliation = Affiliation&.of_professor(p)&.where(end_date: nil)&.last
p.update(institution_id: affiliation&.institution_id)
end
drop_table :affiliations
end
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20240527174758_create_program_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ def up
level = pl.value
program_level = ProgramLevel.create(
level: pl.value,
start_date: pl.updated_at,
start_date: pl.updated_at - 1.month,
)
pl = pl.paper_trail.previous_version
while pl.present?
if pl.value != level
end_date = program_level.start_date
start_date = pl.updated_at
end_date = program_level.start_date - 1.month
start_date = pl.updated_at - 1.month
level = pl.value
program_level = ProgramLevel.create(
level: level,
end_date: end_date,
start_date: start_date,
)
else
start_date = pl.updated_at
start_date = pl.updated_at - 1.month
program_level.update(start_date: start_date)
end
pl = pl.paper_trail.previous_version
Expand Down

0 comments on commit 87fce7f

Please sign in to comment.