Skip to content
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

Data migrations for adding recruitment cycles to database #10320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/models/recruitment_cycle_timetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ def cycle_range
end

def sequential_dates
required_dates = [
return if [
elceebee marked this conversation as resolved.
Show resolved Hide resolved
find_opens_at,
apply_opens_at,
apply_deadline_at,
reject_by_default_at,
decline_by_default_at,
find_closes_at,
]

return if required_dates.any?(&:blank?)
].any?(&:blank?)

if find_opens_at.after? apply_opens_at
errors.add(:apply_opens_at, :apply_opens_after_find_opens)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module DataMigrations
class AddAllRecruitmentCycleTimetablesToDatabase
TIMESTAMP = 20250129093844
MANUAL_RUN = false

def change
CYCLE_DATES.each do |recruitment_cycle_year, dates|
RecruitmentCycleTimetable.find_or_create_by(recruitment_cycle_year:).tap do |timetable|
timetable.update(
find_opens_at: dates[:find_opens],
apply_opens_at: dates[:apply_opens],
apply_deadline_at: dates[:apply_deadline],
reject_by_default_at: dates[:reject_by_default],
decline_by_default_at: dates[:find_closes] - 1.day,
find_closes_at: dates[:find_closes],
christmas_holiday_range: dates.dig(:holidays, :christmas),
easter_holiday_range: dates.dig(:holidays, :easter),
)
end
end
end
end
end
6 changes: 3 additions & 3 deletions config/initializers/cycle_timetables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
reject_by_default: Time.zone.local(2026, 9, 24, 23, 59, 59), # CONFIRMED
find_closes: Time.zone.local(2026, 9, 30, 23, 59, 59), # CONFIRMED
holidays: {
christmas: Date.new(2026, 12, 18)..Date.new(2026, 1, 5), # TBD
christmas: Date.new(2025, 12, 18)..Date.new(2026, 1, 5), # TBD
easter: Date.new(2026, 3, 23)..Date.new(2026, 4, 6), # TBD
},
},
Expand All @@ -55,7 +55,7 @@
find_closes: Time.zone.local(2027, 9, 30, 23, 59, 59), # TBD
holidays: {
christmas: Date.new(2026, 12, 18)..Date.new(2027, 1, 5), # TBD
easter: Date.new(2026, 3, 15)..Date.new(2027, 3, 29), # TBD
easter: Date.new(2027, 3, 15)..Date.new(2027, 3, 29), # TBD
},
},
}.freeze
Expand All @@ -79,7 +79,7 @@
apply_1_deadline: Time.zone.local(2020, 8, 24, 18),
apply_2_deadline: Time.zone.local(2020, 9, 18, 18),
apply_deadline: Time.zone.local(2020, 9, 18, 18), # Adding an 'apply_deadline' for backward compatibility.
reject_by_default: Time.zone.local(2021, 9, 29, 23, 59, 59),
reject_by_default: Time.zone.local(2020, 9, 29, 23, 59, 59),
find_closes: Time.zone.local(2020, 10, 3, 23, 59, 59),
holidays: {},
},
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/data.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DATA_MIGRATION_SERVICES = [
# do not delete or edit this line - services added below by generator
'DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase',
'DataMigrations::RemoveOneLoginPreReleaseBannersFeatureFlag',
'DataMigrations::RemoveNewWithdrawalReasonsFeatureFlag',
'DataMigrations::RemoveUnusedFeatureFlags',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rails_helper'

RSpec.describe DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase do
it 'adds all recruitment cycles to database' do
described_class.new.change
expect(RecruitmentCycleTimetable.pluck(:recruitment_cycle_year))
.to contain_exactly(2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027)
end

it 'handles holidays as expected' do
described_class.new.change
year_without_holidays = RecruitmentCycleTimetable.find_by(recruitment_cycle_year: 2020)
year_with_holidays = RecruitmentCycleTimetable.find_by(recruitment_cycle_year: 2021)

expect(year_without_holidays.easter_holiday_range).to be_nil
expect(year_without_holidays.christmas_holiday_range).to be_nil

expect(year_with_holidays.easter_holiday_range.begin).to eq Date.new(2021, 4, 2)
expect(year_with_holidays.easter_holiday_range.end).to eq Date.new(2021, 4, 17)

expect(year_with_holidays.christmas_holiday_range.begin).to eq Date.new(2020, 12, 20)
expect(year_with_holidays.christmas_holiday_range.end).to eq Date.new(2021, 1, 2)
end

it 'does not create duplicates if run twice' do
described_class.new.change
expect(RecruitmentCycleTimetable.count).to eq 9
described_class.new.change
expect(RecruitmentCycleTimetable.count).to eq 9
end

it 'reverts any changes to the original data' do
described_class.new.change
timetable = RecruitmentCycleTimetable.last
original_find_opens_at = timetable.find_opens_at

timetable.update(find_opens_at: original_find_opens_at - 1.day)
described_class.new.change
expect(timetable.reload.find_opens_at).to eq original_find_opens_at
end
end
Loading