7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/duly_noted/updater.rb', line 7
def update_schema(schema_version, redis)
time = Time.now
if schema_version === ["1","0","0"]
puts "Updating schema to comply with duly_noted 1.0.1"
metrics = redis.smembers "dn:metrics"
metrics.each do |metric|
keys = find_keys(metric, redis)
keys.each do |key|
events = redis.zrange key, 0, -1
events.each do |event|
id = redis.incr "dnid"
redis.zadd(key, redis.zscore(key, event), event.gsub(/:\d{10}.\d+:/, ":#{id}:"))
redis.set("dnid:#{id}", "#{key}:#{id}:meta")
if(redis.exists(event))
redis.mapped_hmset "#{key}:#{id}:meta", redis.hgetall(event)
redis.del(event)
end
redis.zrem(key, event)
end
end
end
redis.keys("*:ref:*").each do |ref_keys|
redis.del(ref_keys)
end
schema_version = ["1","0","1"]
end
if schema_version === ["1","0","1"]
puts "Updating schema to comply with duly_noted 1.0.2"
redis.keys("dnid:*").each do |id_key|
redis.expire id_key, Configuration.editable_for
end
schema_version = ["1","0","2"]
end
redis.set "dn:version", VERSION
puts "All up to date. Completed updates in #{Time.now-time} seconds."
return true
end
|