Skip to content

Commit 7555981

Browse files
committed
Add task to delete sessions without dates
This allows us to migrate the existing teams over to using the new model where we won't create sessions automatically, and instead teams are expected to create their own sessions on an individual basis. This is a script that we only need to run once so I've written it as a Rake task, and already run in QA and test. Jira-Issue: MAV-2741
1 parent 6960096 commit 7555981

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/tasks/data_migration.rake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,22 @@ namespace :data_migration do
55
task delete_clinic_session_notifications: :environment do
66
SessionNotification.where(type: [1, 2]).delete_all
77
end
8+
9+
desc "Delete sessions that have not been scheduled."
10+
task delete_unscheduled_sessions: :environment do
11+
destroyed_sessions =
12+
Session
13+
.where(dates: [])
14+
.find_each
15+
.filter_map do |session|
16+
next if session.consent_notifications.exists?
17+
next if session.session_notifications.exists?
18+
next if session.vaccination_records.exists?
19+
next if ConsentForm.where(original_session: session).exists?
20+
21+
session.tap(&:destroy!)
22+
end
23+
24+
puts "Deleted #{destroyed_sessions.count} sessions"
25+
end
826
end

0 commit comments

Comments
 (0)