-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1522 from OpenC3/activity
Add uuid to activities
- Loading branch information
Showing
18 changed files
with
379 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
openc3/lib/openc3/migrations/20240915000000_activity_uuid.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'openc3/utilities/migration' | ||
require 'openc3/models/scope_model' | ||
require 'openc3/models/timeline_model' | ||
|
||
module OpenC3 | ||
class ActivityUuid < Migration | ||
def self.run | ||
ScopeModel.names.each do |scope| | ||
TimelineModel.names.each do |key| | ||
name = key.split('__').last | ||
json = Store.zrange("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", 0, -1) | ||
parsed = json.map { |value| JSON.parse(value, :allow_nan => true, :create_additions => true) } | ||
parsed.each_with_index do |activity, index| | ||
if activity['uuid'].nil? | ||
activity['uuid'] = SecureRandom.uuid | ||
Store.zrem("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", json[index]) | ||
Store.zadd("#{scope}#{ActivityModel::PRIMARY_KEY}__#{name}", activity['start'], JSON.generate(activity)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
unless ENV['OPENC3_NO_MIGRATE'] | ||
OpenC3::ActivityUuid.run | ||
end |
Oops, something went wrong.