You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
apogee/migrations/2022-01-12-migration-hierar...

24 lines
551 B
Ruby

#!/usr/bin/ruby
require 'fileutils'
Dir.children("data/statuses/").each {|child|
if /^([0-9]+)\.json$/ =~ child
id = $1.to_i
millions = id / 1000000
thousands = id % 1000000 / 1000
ones = id % 1000
target_file = "data/statuses/#{"%03d"%millions}m/#{"%03d"%thousands}k/#{"%03d"%ones}.json"
dirname = File.dirname(target_file)
if( !File.exist?(dirname))
puts "dirname=#{dirname}"
FileUtils.mkdir_p(dirname)
end
puts "data/statuses/#{child} -> #{target_file}"
FileUtils.move("data/statuses/#{child}",target_file);
end
}