added script to delete test users
authorelijah <elijah@riseup.net>
Fri, 21 Aug 2015 05:21:51 +0000 (22:21 -0700)
committerelijah <elijah@riseup.net>
Fri, 21 Aug 2015 05:21:51 +0000 (22:21 -0700)
ruby/destroy-all-test-users [new file with mode: 0755]
ruby/destroy-all-user-dbs [new file with mode: 0755]

diff --git a/ruby/destroy-all-test-users b/ruby/destroy-all-test-users
new file mode 100755 (executable)
index 0000000..45d7055
--- /dev/null
@@ -0,0 +1,32 @@
+#!/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!
diff --git a/ruby/destroy-all-user-dbs b/ruby/destroy-all-user-dbs
new file mode 100755 (executable)
index 0000000..84cec56
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/ruby
+
+require 'couchrest'
+
+server = CouchRest::Server.new
+
+server.databases.each do |db_name|
+  if db_name =~ /^user-[a-f0-9]{32}$/
+    server.database(db_name).delete!
+  end
+end
+
+
+