madrahimov

Untitled

Sep 27th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. tables = Restaurant.find_by_sql("
  2. SELECT nspname || '.' || relname AS relation,
  3. pg_size_pretty(pg_relation_size(C.oid)) AS size
  4. FROM pg_class C
  5. LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
  6. WHERE nspname NOT IN ('pg_catalog', 'information_schema')
  7. And relname like 'bill_calculations_%'
  8. ORDER BY pg_relation_size(C.oid) DESC")
  9.  
  10. ids = []
  11. tables.each do |t|
  12. id = t.relation.split('public.bill_calculations_')[1].gsub('_', '-')
  13. ids << id if id.to_s != 'copy-pkey'
  14. end
  15. ids.each_with_index do |id, i|
  16. r = Restaurant.find_by_id(id)
  17. if r
  18. r.shard = "staging_shard#{i%4}"
  19. r.save
  20. end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment