Skip to content

Commit

Permalink
SL-280: Add task to associate tenant id with all existing recordings (#…
Browse files Browse the repository at this point in the history
…942)

* SL-280: Add task to associate tenant id with all existing recordings

* update readme

* change task name

* fix key, add success message

---------

Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com>
  • Loading branch information
Mariam05 and farhatahmad authored May 24, 2023
1 parent 837c872 commit a66f503
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ id: 4f3e4bb8-2a4e-41a6-9af8-0678c651777f
name: tenant2
secrets: secret2:secret2a:secret2b
```
#### Associate Old Recordings with a Tenant
`./bin/rake recordings:addToTenant[tenant-id]`

If you are switching over from single-tenancy to multitenancy, the existing recordings will have to be transferred to the new tenant. The above task updates the recordings' metadata with the tenant id.

### Customizing Strings

Expand Down
20 changes: 20 additions & 0 deletions lib/tasks/recordings.rake
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,24 @@ namespace :recordings do
end
end
end

desc 'Associate any existing recordings with a tenant'
task :addToTenant, [:tenant_id] => :environment do |_t, args|
tenant_id = args[:tenant_id]
unless tenant_id
puts('No tenant ID was provided')
exit(1)
end

Recording.all.each do |rec|
next if rec.metadata.exists?(key: 'tenant-id')
begin
Metadatum.create!(recording_id: rec.id, key: 'tenant-id', value: tenant_id)
rescue ActiveRecord::RecordInvalid => e
puts("Error creating metadatum record for recording with id #{rec.id}: #{e}")
end
end

puts("All existing recordings have been successfully linked to tenant #{tenant_id}")
end
end

0 comments on commit a66f503

Please sign in to comment.