Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tables = Restaurant.find_by_sql("
- SELECT nspname || '.' || relname AS relation,
- pg_size_pretty(pg_relation_size(C.oid)) AS size
- FROM pg_class C
- LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
- WHERE nspname NOT IN ('pg_catalog', 'information_schema')
- And relname like 'bill_calculations_%'
- ORDER BY pg_relation_size(C.oid) DESC")
- ids = []
- tables.each do |t|
- id = t.relation.split('public.bill_calculations_')[1].gsub('_', '-')
- ids << id if id.to_s != 'copy-pkey'
- end
- ids.each_with_index do |id, i|
- r = Restaurant.find_by_id(id)
- if r
- r.shard = "staging_shard#{i%4}"
- r.save
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment