From 8d78d898d9b3aa176f0f004cab53e02820696323 Mon Sep 17 00:00:00 2001 From: Samuel Couillard <43917914+scouillard@users.noreply.github.com> Date: Fri, 28 Oct 2022 11:02:55 -0400 Subject: [PATCH] Resources migration: Added `migrations:rooms` task (#4013) * Initial commit * Fix path * Add owner_email and owner_provider attributes * Add to_datetime to last_session * Add range to rooms migration * quickfix * Change user to owner and add id to Room select * Revert last commit --- lib/tasks/migrations/migrations.rake | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/tasks/migrations/migrations.rake b/lib/tasks/migrations/migrations.rake index 4c9c9f21..3c97dc46 100644 --- a/lib/tasks/migrations/migrations.rake +++ b/lib/tasks/migrations/migrations.rake @@ -74,6 +74,43 @@ namespace :migrations do exit has_encountred_issue end + task :rooms, [:start, :stop] => :environment do |_task, args| + start, stop = range(args) + has_encountred_issue = 0 + + Room.select(:id, :uid, :name, :bbb_id, :last_session, :user_id) + .find_each(start: start, finish: stop, batch_size: COMMON[:batch_size]).each do |r| + params = { room: { friendly_id: r.uid, + name: r.name, + meeting_id: r.bbb_id, + last_session: r.last_session&.to_datetime, + owner_email: r.owner.email } } + response = Net::HTTP.post(uri('rooms'), payload(params), COMMON[:headers]) + + case response + when Net::HTTPCreated + puts green "Succesfully migrated Room:" + puts cyan " UID: #{r.uid}" + puts cyan " Name: #{r.name}" + else + puts red "Unable to migrate Room:" + puts yellow " UID: #{r.uid}" + puts yellow " Name: #{r.name}" + has_encountred_issue = 1 # At least one of the migrations failed. + end + end + + puts + puts green "Rooms migration completed." + + unless has_encountred_issue.zero? + puts yellow "In case of an error please retry the process to resolve." + puts yellow "If you have not migrated your users, kindly run 'rake migrations:users' first and then retry." + end + + exit has_encountred_issue + end + private def encrypt_params(params) -- GitLab