#!/usr/bin/ruby # # Clean up cruft left over by bad tests. # # Removes all 'test_user_x' users from the users db, along with the # corresponding indentities and storage db. # require 'couchrest' users_db_name = 'users' #user_db_name = 'tmp_users' identities_db_name = 'identities' server = CouchRest::Server.new users_db = server.database(users_db_name) identities_db = server.database(identities_db_name) records = db.view('User/by_login', :reduce => false, :startkey => 'test_user_', :endkey => 'test_user_'+"\u{fff}")['rows'] records.each do |record| user_id = record['id'] username = record['key'] storage_db = server.database("user-" + user_id) storage_db.delete! rescue RestClient::ResourceNotFound identities_db.view('Identity/by_user_id', :reduce => false, :startkey => user_id, :endkey => user_id)['rows'].each do |row| identities_db.delete_doc(row['id']) end end users_db.compact! identities_db.compact!